Skip to content

Add tree shaking #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
"files": [
"dist"
],
"main": "./dist/index.umd.cjs",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"sideEffects": false,
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.umd.cjs"
"require": "./dist/index.cjs"
}
},
"keywords": [
Expand Down
22 changes: 15 additions & 7 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,27 @@ export default defineConfig({
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, 'src/lib/index.ts'),
name: 'Library name',
// the proper extensions will be added
fileName: 'index',
fileName: (format, entryName) => {
if (entryName === 'src/lib/index') {
// Create entry file(s) inside the bundle
return `index.${format === 'es' ? 'js' : 'cjs'}`;
} else if (entryName.includes('node_modules')) {
// Organize external dependencies which included in the bundle
return `external/module.${format === 'es' ? 'js' : 'cjs'}`;
}
// Keep other modules in places
return `${entryName}.${format === 'es' ? 'js' : 'cjs'}`;
},
// Change bundle formats to ES Modules and commonJS.
// UMD bundle will not work with preserveModules:true
formats: ['es', 'cjs'],
},
rollupOptions: {
// make sure to externalize deps that shouldn't be bundled
// into your library
external: external(),
output: {
// Provide global variables to use in the UMD build
// for externalized deps
globals: {
react: 'React',
},
preserveModules: true,
},
},
},
Expand Down