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

Cherry-pick terser to webpack 4 #8392

Merged
merged 3 commits into from Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/createBenchmark.js
Expand Up @@ -15,7 +15,7 @@ webpack(
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.IgnorePlugin(/^(fsevents|uglify-js)$/),
new webpack.IgnorePlugin(/^(fsevents|terser)$/),
new webpack.NormalModuleReplacementPlugin(
/^.\/loadLoader$/,
path.resolve(__dirname, "./createBenchmark/loadLoader")
Expand Down
2 changes: 1 addition & 1 deletion examples/code-splitted-css-bundle/README.md
Expand Up @@ -101,7 +101,7 @@ Child extract-text-webpack-plugin ../../node_modules/extract-text-webpack-plugin
+ 1 hidden module
```

## Minimized (uglify-js, no zip)
## Minimized (terser, no zip)

```
Hash: edbe0e91ba86d814d855
Expand Down
6 changes: 3 additions & 3 deletions lib/WebpackOptionsDefaulter.js
Expand Up @@ -302,10 +302,10 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
this.set("optimization.minimizer", "make", options => [
{
apply: compiler => {
// Lazy load the uglifyjs plugin
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
// Lazy load the Terser plugin
const TerserPlugin = require("terser-webpack-plugin");
const SourceMapDevToolPlugin = require("./SourceMapDevToolPlugin");
new UglifyJsPlugin({
new TerserPlugin({
cache: true,
parallel: true,
sourceMap:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -26,7 +26,7 @@
"node-libs-browser": "^2.0.0",
"schema-utils": "^0.4.4",
"tapable": "^1.1.0",
"uglifyjs-webpack-plugin": "^1.2.4",
"terser-webpack-plugin": "^1.1.0",
"watchpack": "^1.5.0",
"webpack-sources": "^1.3.0"
},
Expand Down
8 changes: 4 additions & 4 deletions test/TestCases.template.js
Expand Up @@ -5,14 +5,14 @@ const path = require("path");
const fs = require("fs");
const vm = require("vm");
const mkdirp = require("mkdirp");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const checkArrayExpectation = require("./checkArrayExpectation");
const createLazyTestEnv = require("./helpers/createLazyTestEnv");

const Stats = require("../lib/Stats");
const webpack = require("../lib/webpack");

const uglifyJsForTesting = new UglifyJsPlugin({
const terserForTesting = new TerserPlugin({
cache: false,
parallel: false,
sourceMap: true
Expand All @@ -31,12 +31,12 @@ const DEFAULT_OPTIMIZATIONS = {
concatenateModules: false,
namedModules: false,
hashedModuleIds: false,
minimizer: [uglifyJsForTesting]
minimizer: [terserForTesting]
};

const NO_EMIT_ON_ERRORS_OPTIMIZATIONS = {
noEmitOnErrors: false,
minimizer: [uglifyJsForTesting]
minimizer: [terserForTesting]
};

const casesPath = path.join(__dirname, "cases");
Expand Down
174 changes: 87 additions & 87 deletions test/__snapshots__/StatsTestCases.test.js.snap

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/cases/parsing/optional-catch-binding/test.filter.js
@@ -1,7 +1,7 @@
const supportsOptionalCatchBinding = require("../../../helpers/supportsOptionalCatchBinding");

module.exports = function(config) {
// XXX: Disable this test if UglifyJS is used because it does not support ES 2019
// XXX: Disable this test if Terser is used because it does not support ES 2019
if (config.mode === "production") {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion test/checkArrayExpectation.js
Expand Up @@ -17,7 +17,7 @@ module.exports = function checkArrayExpectation(
}
let array = object[`${kind}s`].slice().sort();
if (kind === "warning")
array = array.filter(item => !/from UglifyJs/.test(item));
array = array.filter(item => !/from Terser/.test(item));
if (fs.existsSync(path.join(testDirectory, `${filename}.js`))) {
const expectedFilename = path.join(testDirectory, `${filename}.js`);
const expected = require(expectedFilename);
Expand Down
@@ -1,5 +1,5 @@
var webpack = require("../../../../");
var UglifyJsPlugin = require("uglifyjs-webpack-plugin");
var TerserPlugin = require("terser-webpack-plugin");
module.exports = {
node: {
__dirname: false,
Expand All @@ -14,7 +14,7 @@ module.exports = {
},
optimization: {
minimizer: [
new UglifyJsPlugin({
new TerserPlugin({
sourceMap: true
})
]
Expand Down
@@ -1,4 +1,4 @@
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
node: {
__dirname: false,
Expand All @@ -17,21 +17,21 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new UglifyJsPlugin({
new TerserPlugin({
cache: false,
parallel: false,
exclude: ["vendors.js", "extract.js"]
}),
new UglifyJsPlugin({
new TerserPlugin({
cache: false,
parallel: false,
extractComments: true,
include: ["extract.js"]
}),
new UglifyJsPlugin({
new TerserPlugin({
cache: false,
parallel: false,
uglifyOptions: {
terserOptions: {
compress: {
passes: 2
}
Expand Down
14 changes: 7 additions & 7 deletions test/statsCases/filter-warnings/webpack.config.js
@@ -1,4 +1,4 @@
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const baseConfig = {
mode: "production",
entry: "./index",
Expand All @@ -8,9 +8,9 @@ const baseConfig = {
optimization: {
minimize: true,
minimizer: [
new UglifyJsPlugin({
new TerserPlugin({
sourceMap: true,
uglifyOptions: {
terserOptions: {
compress: {
warnings: true
},
Expand All @@ -34,11 +34,11 @@ const baseConfig = {

module.exports = [
undefined,
"UglifyJs",
/UglifyJs/,
"Terser",
/Terser/,
warnings => true,
["UglifyJs"],
[/UglifyJs/],
["Terser"],
[/Terser/],
[warnings => true],
"should not filter",
/should not filter/,
Expand Down
@@ -1,4 +1,4 @@
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
mode: "production",
entry: "./index",
Expand All @@ -8,9 +8,9 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new UglifyJsPlugin({
new TerserPlugin({
sourceMap: true,
uglifyOptions: {
terserOptions: {
compress: {
warnings: true
},
Expand All @@ -21,7 +21,7 @@ module.exports = {
},
warnings: true
},
warningsFilter(filename) {
warningsFilter(message, filename) {
return /a\.js$/.test(filename);
}
})
Expand Down