question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tree shaking completely broken?

See original GitHub issue

updated 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')
)

Webpack & Rollup test repo

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:62
  • Comments:163 (21 by maintainers)

github_iconTop GitHub Comments

70reactions
danbucholtzcommented, Jan 23, 2017

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

60reactions
TheLarkInncommented, Jan 18, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found