-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guides - Issues with Tree Shaking & Production #1331
Comments
The production guide suggests: new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}) …will perform tree-shaking, but that plugin appears to be deprecated, and doesn't appear to be handling tree-shaking. |
After playing about with this, it seems like Uglify is responsible for actually removing the unused code - Webpack's role in tree shaking appears to be avoiding generating You can give |
Yeah, it seems to behave that way. Babili does the same. I guess the docs led me to think the code removal was performed by webpack. |
@insin @jakearchibald I've seen a few other discussions recently that all came to the same conclusion as well. Essentially it's the combination of ES6 static |
This continues our work #1258 and resolves the issues mentioned in #1331. The updates to tree-shaking were more just clean up and synchronization while production included more significant changes and a strong recommendation of `webpack-merge`. The old guide pointed out that _you could_ just maintain two separate configs and duplicate the overlap but I don't think we should recommend this. Resolves #1331
I was trying to get tree shaking working. Here are a few notes about the tree shaking and production guides:
The article explains what tree shaking is (really well), but it doesn't really cover how to achieve it.
--optimize-minimize
will do it, but that also throws in uglify, which can make it difficult to confirm if treeshaking has worked, and will throw errors if you're using ES2016+.One of the guides should cover how to enable tree shaking without enabling other optimisations. This will help users confirm that code is being removed, without having to read minified code.
The production guide should cover how to avoid errors when using ES2016+, either by using the uglify harmony branch, or BabiliWebpackPlugin. None of the docs I've seen cover how to use BabiliWebpackPlugin instead of uglify while retaining tree shaking.
Tree shaking will break if using babel + the es2015 preset, as it transpiles the imports. I've filed babel/babel-loader#477, but it may be worth mentioning in the guide too.
The text was updated successfully, but these errors were encountered: