Skip to content

Commit

Permalink
chore: enable minify for dist build
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed May 31, 2023
1 parent 0c50c14 commit e0e1415
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
18 changes: 14 additions & 4 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
}
Expand All @@ -61,7 +71,7 @@ export default defineConfig([{
output: {
dir: 'dist',
format: 'commonjs',
entryFileNames: '[name].d.ts'
entryFileNames: '[name]/index.d.ts'
},
plugins: [dts()]
}]);
10 changes: 5 additions & 5 deletions tools/postbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
};
});

Expand Down

0 comments on commit e0e1415

Please sign in to comment.