@@ -13,76 +13,76 @@ import packageJson from './package.json' assert { type: 'json' };
1313// suppresses warnings printed to console as part of bundling components with directives present.
1414const onWarnSuppression = {
1515 onwarn ( warning , warn ) {
16- if ( warning . code === 'MODULE_LEVEL_DIRECTIVE' && warning . message . includes ( `"use client"` ) ) {
17- return ;
18- }
16+ if ( warning . code === 'MODULE_LEVEL_DIRECTIVE' && warning . message . includes ( `"use client"` ) ) return ;
1917 warn ( warning ) ;
2018 } ,
2119} ;
2220
23- const commonPlugins = [ external ( ) , tsPaths ( ) , resolve ( ) , commonjs ( ) ] ;
21+ // Keep react 19 out of the bundle
22+ const externals = [ 'react' , 'react-dom' , 'react/jsx-runtime' ] ;
23+
24+ const commonPlugins = [
25+ external ( ) , // auto-externalize peer deps
26+ tsPaths ( ) , // respect tsconfig paths in source
27+ resolve ( { extensions : [ '.mjs' , '.js' , '.ts' , '.tsx' ] } ) ,
28+ commonjs ( ) ,
29+ ] ;
2430
2531export default [
26- // cjs export
32+ // CJS (single file)
2733 {
2834 input : 'src/index.ts' ,
35+ external : externals ,
2936 output : [
3037 {
31- file : packageJson . main ,
38+ file : packageJson . main , // e.g. dist/cjs/index.js
3239 format : 'cjs' ,
3340 sourcemap : true ,
3441 } ,
3542 ] ,
3643 plugins : [
3744 ...commonPlugins ,
3845 typescript ( {
39- tsconfig : 'bundle-base.tsconfig.json' ,
40- compilerOptions : {
41- declaration : false ,
42- } ,
46+ // IMPORTANT: dedicated build tsconfig (noEmit, no jest/node types)
47+ tsconfig : './tsconfig.build.json' ,
4348 } ) ,
44- terser ( ) ,
49+ preserveDirectives ( ) , // keep "use client" etc.
50+ terser ( { compress : { directives : false } } ) ,
4551 ] ,
4652 ...onWarnSuppression ,
4753 } ,
48- // esm export
54+
55+ // ESM (single file)
4956 {
5057 input : 'src/index.ts' ,
58+ external : externals ,
5159 output : [
5260 {
53- dir : packageJson . module ,
61+ file : packageJson . module , // e.g. dist/esm/index.js
5462 format : 'esm' ,
5563 sourcemap : true ,
56- preserveModules : true ,
57- preserveModulesRoot : 'src' ,
5864 } ,
5965 ] ,
6066 plugins : [
6167 ...commonPlugins ,
6268 typescript ( {
63- tsconfig : 'bundle-base.tsconfig.json' ,
64- compilerOptions : {
65- declaration : true ,
66- declarationDir : 'dist/esm' ,
67- emitDeclarationOnly : true ,
68- outDir : 'dist/esm' ,
69- } ,
69+ tsconfig : './tsconfig.build.json' ,
7070 } ) ,
7171 preserveDirectives ( ) ,
7272 terser ( { compress : { directives : false } } ) ,
7373 ] ,
7474 ...onWarnSuppression ,
7575 } ,
76- // type bundling
76+
77+ // Type definitions (bundled .d.ts)
7778 {
7879 input : 'src/index.ts' ,
80+ external : externals ,
7981 output : [ { file : 'dist/index.d.ts' , format : 'esm' } ] ,
80- external : [ ] ,
8182 plugins : [
8283 dts ( {
83- compilerOptions : {
84- paths : tsBuildConfig . compilerOptions . paths ,
85- } ,
84+ // carry over path mapping if you have any
85+ compilerOptions : { paths : tsBuildConfig ?. compilerOptions ?. paths ?? { } } ,
8686 } ) ,
8787 ] ,
8888 } ,
0 commit comments