Tree shaking completely broken?
See original GitHub issueupdated with the latest versions (29.06.2017) Webpack - 3.0.0 Babel-preset-env - 1.5.2 Node - 8.1.2 OS X - 10.12.5
Current
Tree shaking is not removing imports, not used in the app.
Expected
Tree shaking, removing not used imports.
The test case is a simple app with React & React Router v4. Link
component is not used, but the whole router package is bundled.
import React from 'react'
import ReactDOM from 'react-dom'
import { Link } from 'react-router-dom'
ReactDOM.render(
<p>Hey</p>,
document.getElementById('app')
)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:62
- Comments:163 (21 by maintainers)
Top Results From Across the Web
Tree-Shaking: A Reference Guide - Smashing Magazine
Simply put, tree-shaking means removing unreachable code (also known as dead code) from a bundle. As Webpack version 3's documentation states: “ ...
Read more >Tree shaking and code splitting in webpack - LogRocket Blog
Tree shaking, also known as dead code elimination, is the practice of removing unused code in your production build. It's important to ship...
Read more >Tree-shaking in real world: what could go wrong? - Medium
Tree-shaking is the process of detecting and marking dead code in your bundle based on ES modules' usage of import and export statements....
Read more >why is tree-shaking hard? - Google Groups
>I understand that allowing EVAL would make tree-shaking impossible, ... (no longer supported) completely ignored the possibility of functions becoming
Read more >Tree Shaking - webpack
Tree shaking is a term commonly used in the JavaScript context for dead-code elimination. It relies on the static structure of ES2015 module...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Tree shaking should occur independently from minification/dead code removal IMO if possible. Otherwise it really doesn’t rely on Webpack, it relies on a different 3rd party tool.
For example, when I run Rollup to produce a bundle, it’s tree shaken without any sort of minification or dead code removal.
This is important for the Ionic Framework team because in order to support Webpack, Closure Compiler and Rollup independently, we run minification/dead code removal as a separate step independent from the bundling process.
Thanks, Dan
Thank you everyone for keeping this issue up to date. I have to apologize for not communicating the update on how we plan to tackle this issue.
So after we have finished our 2.3 regression milestone for bugfixes for webpack 2(.2) final, we start on features.
Therefore I’m going to add this to our feature milestone.
So tl;dr https://github.com/mishoo/UglifyJS2/issues/1261 is the biggest hurdle on solving this problem. So we either have to:
See if implement scope hoisting (rollup features) or build a new general purpose optimizer that supports a level of program flow analysis.
We would really appreciate as much brainstorming as possible to how we could solve this.