Skip to content

Commit

Permalink
Use tsup instead of tsdx
Browse files Browse the repository at this point in the history
This gives us more control about the build process
* Expose `react-hot-toast/headless` - Fixes #39
* Bundle size is even smaller now

TODO:
* Find alternative for `tsdx lint` and possibly `tsdx test`
  • Loading branch information
timolins committed Jul 8, 2022
1 parent e77d701 commit d58cb35
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 51 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
node_modules
.cache
dist
/headless
.vscode
.vercel
38 changes: 28 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,29 @@
"version": "2.2.0",
"author": "Timo Lins",
"license": "MIT",
"sideEffects": false,
"repository": "timolins/react-hot-toast",
"keywords": [
"react",
"notifications",
"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"
Expand All @@ -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",
Expand All @@ -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": {
Expand All @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions src/headless/index.ts
Original file line number Diff line number Diff line change
@@ -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;
29 changes: 2 additions & 27 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -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<TValue, TArg> = _ValueOrFunction<TValue, TArg>;
export type ToasterProps = _ToasterProps;
export type DefaultToastOptions = _DefaultToastOptions;
export type IconTheme = _IconTheme;
export type ToastType = _ToastType;
export type ValueFunction<TArg, TValue> = _ValueFunction<TArg, TValue>;

export { toast };
export default toast;
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 26 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -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',
},
]);
12 changes: 0 additions & 12 deletions types/goober.d.ts

This file was deleted.

0 comments on commit d58cb35

Please sign in to comment.