-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Description
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
- index.js
import { internal } from './lib'
console.log('outer',internal);
- lib.js
export const answer = 42;
export const secret = 10;
console.log('lib'); // because internal comes from reexport other than lib.js, so this side effect could be shaked
export { internal } from './reexport';
- reexport.js
console.log('internal');
export const internal = 100;
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
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.
hyrious, AntonioMeireles and Sunny-117
Metadata
Metadata
Assignees
Labels
No labels