Test your javascript module bundler (Webpack, Rollup, etc) and find out which one is the smartest when it comes to intelligently eliminating unused code.
See the original discussion in webpack
repo
This is the test cases comparison table: ✓
means the test passes.
Bundler | "sample" |
---|---|
Webpack 2 + Babili | ✓ |
Webpack 2 + UglifyJS | ✓ |
Rollup | ✓ |
Make up your own test cases which not all bundlers pass and send pull requests. Use the tests/sample
folder as an example.
When Webpack 2 detects an unused ES6 export it marks it with /* unused harmony export */
but still does output it in the resulting bundle. Such unused exports will be removed when minimizing the bundle using either Babili (recommended) or UglifyJSPlugin
(legacy) (therefore Webpack 2 doesn't remove unused code itself instead relying on a 3rd party plugin for doing that). In contrast, Rollup does remove unused ES6 exports before the output bundle is minimized.
# Make sure Node.js >= 7.x.x is installed
git clone https://github.com/halt-hammerzeit/es6-tree-shaking-test.git
cd es6-tree-shaking-test
npm install
npm test [test-case-name]