Skip to content
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

Merged
merged 3 commits into from
Sep 16, 2018
Merged

Switch from uglifyjs-webpack-plugin to terser-webpack-plugin #8036

merged 3 commits into from
Sep 16, 2018

Conversation

edmorley
Copy link
Contributor

@edmorley edmorley commented Sep 15, 2018

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
  • which led to a fork called terser that has incorporated all of the unmerged PRs and will be where all new development occurs
  • terser-webpack-plugin was created, which is the terser equivalent of uglifyjs-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 to terser-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:

  • requires the minifier options to be passed under terserOptions, rather than the previous uglifyOptions.
  • has changed the method signature that should be used when specifying a warningsFilter function.

What needs to be documented once your changes are merged?

@webpack-bot
Copy link
Contributor

webpack-bot commented Sep 15, 2018

For maintainers only:

  • This need to be documented (issue in webpack/webpack.js.org will be filed when merged)

@webpack-bot
Copy link
Contributor

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]"
Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edmorley yep

@webpack-bot
Copy link
Contributor

@edmorley Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

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.
@edmorley
Copy link
Contributor Author

Ah good spot on the warningsFilter signature change - thank you for adding a fix.

@sokra sokra merged commit b7128d8 into webpack:next Sep 16, 2018
@webpack-bot
Copy link
Contributor

I've created an issue to document this in webpack/webpack.js.org.

@sokra
Copy link
Member

sokra commented Sep 16, 2018

Thanks

montogeek pushed a commit to webpack/webpack.js.org that referenced this pull request Sep 18, 2018
)

* 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
clarkdo pushed a commit to nuxt/nuxt that referenced this pull request Sep 20, 2018
<!--- 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.
jakemarsden added a commit to jakemarsden/aikido-track that referenced this pull request Oct 11, 2018
For the same reasons as webpack/webpack#8036
Webpack will switch to terser by default for 5.x
hectorgrebbell added a commit to hectorgrebbell/mini-css-extract-plugin that referenced this pull request Mar 8, 2019
Webpack has moved to Terser so it feels like the documentation here should too

webpack/webpack#8036
foolip added a commit to GoogleChromeLabs/confluence that referenced this pull request May 13, 2019
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.
foolip added a commit to GoogleChromeLabs/confluence that referenced this pull request May 13, 2019
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.
foolip added a commit to GoogleChromeLabs/confluence that referenced this pull request May 13, 2019
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants