diff --git a/.gitignore b/.gitignore index f2e5749..53afc2f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ node_modules .cache dist +/headless +.vscode .vercel diff --git a/package.json b/package.json index 004123c..a9182ba 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "version": "2.2.0", "author": "Timo Lins", "license": "MIT", - "sideEffects": false, "repository": "timolins/react-hot-toast", "keywords": [ "react", @@ -12,9 +11,22 @@ "toast", "snackbar" ], - "main": "dist/index.js", - "typings": "dist/index.d.ts", + "module": "dist/index.esm.js", + "exports": { + "./package.json": "./package.json", + ".": { + "import": "./dist/index.esm.js", + "require": "./dist/index.js", + "types": "./dist/index.d.ts" + }, + "./headless": { + "import": "./headless/index.esm.js", + "require": "./headless/index.js", + "types": "./headless/index.d.ts" + } + }, "files": [ + "headless", "dist", "src", "types" @@ -23,8 +35,8 @@ "node": ">=10" }, "scripts": { - "start": "tsdx watch", - "build": "tsdx build", + "start": "tsup --watch", + "build": "tsup", "lint": "tsdx lint", "test": "echo \"No test specified\"", "setup": "pnpm i && cd site && pnpm i && cd .. && pnpm run link", @@ -45,15 +57,22 @@ "arrowParens": "always", "trailingComma": "es5" }, - "module": "dist/react-hot-toast.esm.js", "size-limit": [ { - "path": "dist/react-hot-toast.cjs.production.min.js", + "path": "dist/index.js", "limit": "5 KB" }, { - "path": "dist/react-hot-toast.esm.js", + "path": "dist/index.esm.js", "limit": "5 KB" + }, + { + "path": "headless/index.js", + "limit": "2 KB" + }, + { + "path": "headless/index.esm.js", + "limit": "2 KB" } ], "devDependencies": { @@ -63,8 +82,7 @@ "csstype": "^3.0.7", "size-limit": "^4.9.1", "tsup": "^6.1.3", - "typescript": "^4.7.4", - "tsdx": "^0.14.1" + "typescript": "^4.7.4" }, "dependencies": { "goober": "^2.1.10" diff --git a/src/headless/index.ts b/src/headless/index.ts new file mode 100644 index 0000000..115c77c --- /dev/null +++ b/src/headless/index.ts @@ -0,0 +1,21 @@ +import { toast } from '../core/toast'; + +export { + DefaultToastOptions, + IconTheme, + Renderable, + resolveValue, + Toast, + ToasterProps, + ToastOptions, + ToastPosition, + ToastType, + ValueFunction, + ValueOrFunction, +} from '../core/types'; + +export { useToaster } from '../core/use-toaster'; +export { useStore as useToasterStore } from '../core/store'; + +export { toast }; +export default toast; diff --git a/src/index.tsx b/src/index.tsx index fd7f20a..1968353 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,38 +1,13 @@ import { toast } from './core/toast'; -// Type re-export workaround, to stay compatible with TS 3.7 and lower -import { - ToastOptions as _ToastOptions, - ToastPosition as _ToastPosition, - Toast as _Toast, - Renderable as _Renderable, - ValueOrFunction as _ValueOrFunction, - ToasterProps as _ToasterProps, - DefaultToastOptions as _DefaultToastOptions, - IconTheme as _IconTheme, - ToastType as _ToastType, - ValueFunction as _ValueFunction, -} from './core/types'; -export { useToaster } from './core/use-toaster'; +export * from './headless'; + export { ToastBar } from './components/toast-bar'; export { ToastIcon } from './components/toast-icon'; export { Toaster } from './components/toaster'; -export { useStore as useToasterStore } from './core/store'; export { CheckmarkIcon } from './components/checkmark'; export { ErrorIcon } from './components/error'; export { LoaderIcon } from './components/loader'; -export { resolveValue } from './core/types'; - -export type ToastOptions = _ToastOptions; -export type ToastPosition = _ToastPosition; -export type Toast = _Toast; -export type Renderable = _Renderable; -export type ValueOrFunction = _ValueOrFunction; -export type ToasterProps = _ToasterProps; -export type DefaultToastOptions = _DefaultToastOptions; -export type IconTheme = _IconTheme; -export type ToastType = _ToastType; -export type ValueFunction = _ValueFunction; export { toast }; export default toast; diff --git a/tsconfig.json b/tsconfig.json index a5ddfbc..cc14633 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,9 @@ { // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs - "include": ["src", "types"], + "include": ["src", "types", "src/headless/index.ts.ts"], "compilerOptions": { "module": "esnext", "lib": ["dom", "esnext"], - "importHelpers": true, // output .d.ts declaration files for consumers "declaration": true, // output .js.map sourcemap files for consumers diff --git a/tsup.config.ts b/tsup.config.ts new file mode 100644 index 0000000..4ccea59 --- /dev/null +++ b/tsup.config.ts @@ -0,0 +1,26 @@ +import { defineConfig, Options } from 'tsup'; + +const commonConfig: Options = { + minify: true, + dts: true, + format: ['esm', 'cjs'], + sourcemap: true, + clean: true, + outExtension({ format }) { + return { + js: format === 'cjs' ? '.js' : `.${format}.js`, + }; + }, +}; +export default defineConfig([ + { + ...commonConfig, + entry: ['src/index.tsx'], + outDir: 'dist', + }, + { + ...commonConfig, + entry: ['src/headless/index.ts'], + outDir: 'headless', + }, +]); diff --git a/types/goober.d.ts b/types/goober.d.ts deleted file mode 100644 index 434adef..0000000 --- a/types/goober.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import * as goober from 'goober'; -import { Theme } from '../src/core/types'; - -declare module 'goober' { - interface Context { - resource: any; - } - function keyframes( - tag: CSSAttribute | TemplateStringsArray | string, - ...props: Array - ): string; -}