Skip to content
This repository was archived by the owner on Dec 5, 2019. It is now read-only.
This repository was archived by the owner on Dec 5, 2019. It is now read-only.

Tree shaking not working - webpack 4 and uglifyjs-webpack-plugin #267

Closed
@gpspake

Description

@gpspake

I have tried adding UglifyJSPlugin to a webpack 4 project, in accordance with the webpack tree shaking docs, and I'm still seeing dead code and even comments in my bundle which leads me to think that my uglify plugin config isn't being used. I posted this on Stack Overflow a couple of days ago before posting here.

Link to project

The docs state that "in order to take advantage of tree shaking, you must...

  • Use ES2015 module syntax (i.e. import and export). done
  • Add a "sideEffects" entry to your project's package.json file. done .
  • Include a minifier that supports dead code removal (e.g. the UglifyJSPlugin)." done

Still, the unused/unimported leftpad function and comments are being included in my bundle.

All of the config can be seen here. Based on the results I'm seeing, I suspect that this is related to the uglify settings in my webpack config.

To reproduce:

git clone https://github.com/gpspake/es6-todomvc.git
cd es6-todomvc
yarn install
yarn build
# check dist/bundle.js
# comment new UglifyJsPlugin() out in webpack config
yarn build
# check dist/bundle.js - it's identical to the previous bundle

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions