diff --git a/rollup.config.ts b/rollup.config.ts index c4ab4d57..f195f5e6 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -15,6 +15,7 @@ const external = (id: string) => { return externalModules.some((name) => id === name || id.startsWith(`${name}/`)); }; +// Same target as Next.js 13 const targets = browserslist([ 'chrome 64', 'edge 79', @@ -30,25 +31,34 @@ export default defineConfig([{ output: [{ dir: 'dist', format: 'commonjs', - entryFileNames: '[name].cjs' + entryFileNames: '[name]/index.cjs' }, { dir: 'dist', format: 'commonjs', - entryFileNames: '[name].js' + entryFileNames: '[name]/index.js' }, { dir: 'dist', format: 'esm', - entryFileNames: '[name].mjs' + entryFileNames: '[name]/index.mjs' }], plugins: [ swc({ + isModule: true, jsc: { transform: { react: { runtime: 'automatic' } + }, + minify: { + compress: { + passes: 2 + }, + mangle: {}, + module: true } }, + minify: true, env: { targets } @@ -61,7 +71,7 @@ export default defineConfig([{ output: { dir: 'dist', format: 'commonjs', - entryFileNames: '[name].d.ts' + entryFileNames: '[name]/index.d.ts' }, plugins: [dts()] }]); diff --git a/tools/postbuild.ts b/tools/postbuild.ts index 6738a016..69c95868 100644 --- a/tools/postbuild.ts +++ b/tools/postbuild.ts @@ -42,13 +42,13 @@ const distDir = path.resolve(rootDir, 'dist'); Object.keys(entries).forEach(entryName => { packageJsonCopy.exports[`./${entryName}`] = { - types: `./${entryName}.d.ts`, + types: `./${entryName}/index.d.ts`, import: { - types: `./${entryName}.d.ts`, - default: `./${entryName}.mjs` + types: `./${entryName}/index.d.ts`, + default: `./${entryName}/index.mjs` }, - require: `./${entryName}.cjs`, - default: `./${entryName}.js` + require: `./${entryName}/index.cjs`, + default: `./${entryName}/index.js` }; });