-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
treeshaking generate different result from webpack #2049
Comments
To me, what Webpack does is strange. The |
since no spec about tree shaking, I don't know which is right |
Same problem hereComponent library directory structure// package.json
{
"sideEffects": [
"**/*.css"
]
} // index.js
import Drawer from './components/drawer/index.js';
......
export { Drawer, .... } // components/drawer/inde.js
import './style.css'; // This file would be shaked wrongly!
export * from './drawer.js';
export { default } from './drawer.js'; Usage in my projectI used vite(based on rollup or esbuild) to build my project with the following entry: // src/main.js
import { Drawer } from 'my-lib'
... And I found that tree-shaking eliminated my css files that I had listed in export { default } from './drawer.js'; into the below: import drawer from './drawer.js';
export default drawer; Everything works well, I guess that may be a BUG with rollup or esbuild. |
@hardfist But when at development with vite, I didn't get this problem, it only occurred at build time, so I preferred to think of this as rollup's BUG not esbuild. |
you need to provide minimal demo using esbuild | rollup directly |
webpack has a nice feature,when set sideEffects to false, if a import x from b, and x comes from b's reexport from c, then bundler could shake whole side effect in b
different bundler result are shown, and you can see webpack tree shake the lib.js side effect, but esbuild and rollup does not, https://github.com/hardfist/treeshaking-demo
rollup
esbuild
webpack
This feature is documented here https://webpack.js.org/guides/tree-shaking/#clarifying-tree-shaking-and-sideeffects
and vue change sideEffects to true to avoid shaking sideEffects vuejs/core#1263, so I'm wondering whether esbuild could align with webpack or webpack's behavior is not right.
The text was updated successfully, but these errors were encountered: