-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
Switch from uglifyjs-webpack-plugin to terser-webpack-plugin #8036
Conversation
For maintainers only:
|
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
WARNING in UglifyJs Plugin: Dropping unused function someUnRemoteUsedFunction4 [./a.js:6,0] in bundle.js | ||
|
||
WARNING in UglifyJs Plugin: Dropping unused function someUnRemoteUsedFunction5 [./a.js:7,0] in bundle.js" | ||
[2] (webpack)/buildin/module.js 497 bytes {0} [built]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you rename test/statsCases/warnings-uglifyjs
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wonder why this snapshot differs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wonder why this snapshot differs?
It seems that the warnings message format is slightly different between the two plugins:
https://github.com/webpack-contrib/uglifyjs-webpack-plugin/blob/v1.3.0/src/index.js#L121
https://github.com/webpack-contrib/terser-webpack-plugin/blob/v1.1.0/src/index.js#L150
@evilebottnawi is this expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@edmorley yep
Some history: * `uglifyjs-webpack-plugin` < v1.0 used the minifier `uglify-js` * however `uglify-js` does not support ES6, which resulted in a fork called `uglify-es` that was developed in the `uglify-js` repository, but under the `harmony` branch * `uglifyjs-webpack-plugin` v1.x switched to `uglify-es` for ES6 support * however `uglify-es` stopped being maintained: mishoo/UglifyJS#3156 (comment) * which led to a fork called `terser` that has incorporated all of the unmerged PRs and will be where all new development occurs: https://github.com/fabiosantoscode/terser * `terser-webpack-plugin` was created, which is the `terser` equivalent of `uglifyjs-webpack-plugin`: https://github.com/webpack-contrib/terser-webpack-plugin * `uglifyjs-webpack-plugin` v2.x will be switching back to `uglify-js`, so any project that needs to support ES6 now needs to switch to `terser-webpack-plugin`. Fixes #7923.
Ah good spot on the |
I've created an issue to document this in webpack/webpack.js.org. |
Thanks |
) * docs(config): Replace UglifyJSPlugin references with TerserPlugin Since the default `options.minimizer` is now `terser-webpack-plugin`: webpack/webpack#8036 I've also: * updated the custom `minimizer` example to include all of the default options, to reduce the chance people forget to enable them. * removed the `optimize/UglifyJsPlugin` reference, since it's no longer included in the webpack repository. * removed the "Here are a few more popular ones" mention, since it's not accurate (they aren't more popular). * removed manual plugin configuration from `configuration-languages.md` since the defaults for `minimizer` make it unnecessary. Fixes #2520. * Address review comment
<!--- Provide a general summary of your changes in the title above --> ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Description Webpack requires `uglifyjs-webpack-plugin@1.x`. thus `uglifyjs-webpack-plugin@2.x` may not resolve correctly. Also, the webpack team decided to go with `terser-webpack-plugin` (webpack/webpack#8036). ## Checklist: <!--- Put an `x` in all the boxes that apply. --> <!--- If your change requires a documentation PR, please link it appropriately --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. (PR: #) - [ ] I have added tests to cover my changes (if not applicable, please state why) - [ ] All new and existing tests passed.
For the same reasons as webpack/webpack#8036 Webpack will switch to terser by default for 5.x
Webpack has moved to Terser so it feels like the documentation here should too webpack/webpack#8036
The `mode` option needs to be added to webpack config: https://webpack.js.org/migrate/4#mode CommonsChunkPlugin is replaced by new config: https://webpack.js.org/migrate/4#commonschunkplugin https://webpack.js.org/configuration/optimization/#optimizationsplitchunks CleanWebpackPlugin uses webpack's `output.path` by default, so use the default configuration: johnagan/clean-webpack-plugin#106 UglifyjsWebpackPlugin is replaced with TerserWebpackPlugin, which is now webpack's default minimizer: https://webpack.js.org/plugins/terser-webpack-plugin/#terseroptions webpack/webpack#8036 Unfortunately karma-webpack 4.0.0 isn't released yet, so a release candidate is used instead.
The `mode` option needs to be added to webpack config: https://webpack.js.org/migrate/4#mode CommonsChunkPlugin is replaced by new config: https://webpack.js.org/migrate/4#commonschunkplugin https://webpack.js.org/configuration/optimization/#optimizationsplitchunks https://webpack.js.org/plugins/split-chunks-plugin/#split-chunks-example-2 CleanWebpackPlugin uses webpack's `output.path` by default, so use the default configuration: johnagan/clean-webpack-plugin#106 UglifyjsWebpackPlugin is replaced with TerserWebpackPlugin, which is now webpack's default minimizer: https://webpack.js.org/plugins/terser-webpack-plugin/#terseroptions webpack/webpack#8036 Unfortunately karma-webpack 4.0.0 isn't released yet, so a release candidate is used instead.
The `mode` option needs to be added to webpack config: https://webpack.js.org/migrate/4#mode CommonsChunkPlugin is replaced by new config: https://webpack.js.org/migrate/4#commonschunkplugin https://webpack.js.org/configuration/optimization/#optimizationsplitchunks https://webpack.js.org/plugins/split-chunks-plugin/#split-chunks-example-2 CleanWebpackPlugin uses webpack's `output.path` by default, so use the default configuration: johnagan/clean-webpack-plugin#106 UglifyjsWebpackPlugin is replaced with TerserWebpackPlugin, which is now webpack's default minimizer: https://webpack.js.org/plugins/terser-webpack-plugin/#terseroptions webpack/webpack#8036 Unfortunately karma-webpack 4.0.0 isn't released yet, so a release candidate is used instead.
Some history:
uglify-js
does not support ES6, which resulted in a fork called uglify-es that was developed in theuglify-js
repository, but under the harmony branchuglifyjs-webpack-plugin
v1.x switched touglify-es
for ES6 supportuglify-es
stopped being maintainedterser
equivalent ofuglifyjs-webpack-plugin
uglifyjs-webpack-plugin
v2.x has switched back to uglify-js, so any project that needs to support ES6 now needs to switch toterser-webpack-plugin
instead.Fixes #7923.
What kind of change does this PR introduce?
Bugfix (since terser includes many correctness fixes) but also breaking change (see below).
Did you add tests for your changes?
There are existing tests which have been updated for the plugin name change.
Does this PR introduce a breaking change?
Yes. The new plugin:
warningsFilter
function.What needs to be documented once your changes are merged?