Skip to content

Commit 87702a2

Browse files
committed
Updates UglifyJs to 2.8.x to accept additional compress options
Bumps the minimum version of UglifyJs and substitutes `.compress()` for `.transform()` as recommended. In addition to a new test covering `compress` options this commit also contains updates to make existing tests pass with the update.
1 parent d0908fe commit 87702a2

File tree

9 files changed

+188
-147
lines changed

9 files changed

+188
-147
lines changed

input.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invalid javascript

lib/optimize/UglifyJsPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class UglifyJsPlugin {
8787
const compress = uglify.Compressor(options.compress || {
8888
warnings: false
8989
}); // eslint-disable-line new-cap
90-
ast = ast.transform(compress);
90+
ast = compress.compress(ast);
9191
}
9292
if(options.mangle !== false) {
9393
ast.figure_out_scope(options.mangle || {});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"source-map": "^0.5.3",
2121
"supports-color": "^3.1.0",
2222
"tapable": "~0.2.5",
23-
"uglify-js": "^2.7.5",
23+
"uglify-js": "^2.8.5",
2424
"watchpack": "^1.2.0",
2525
"webpack-sources": "^0.1.4",
2626
"yargs": "^6.0.0"

test/UglifyJsPlugin.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe("UglifyJsPlugin", function() {
122122
}], function() {
123123
compilation.errors.length.should.be.exactly(1);
124124
compilation.errors[0].should.be.an.Error;
125-
compilation.errors[0].message.should.have.containEql("SyntaxError");
125+
compilation.errors[0].message.should.have.containEql("Unexpected token");
126126
compilation.errors[0].message.should.have.containEql("[test2.js:1,8]");
127127
});
128128
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function f() {
2+
var a = 1, b = 2, c = 3;
3+
if (a) {
4+
b = c;
5+
} else {
6+
c = b;
7+
}
8+
console.log(a + b);
9+
console.log(b + c);
10+
console.log(a + c);
11+
console.log(a + b + c);
12+
}
13+
14+
module.exports = f;

test/configCases/plugins/uglifyjs-plugin/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,11 @@ it("should remove extracted comments and insert a banner", function() {
4444
source.should.containEql("/*! For license information please see extract.js.LICENSE */");
4545
});
4646

47+
it("should pass compress options", function() {
48+
var fs = require("fs"),
49+
path = require("path");
50+
var source = fs.readFileSync(path.join(__dirname, "compress.js"), "utf-8");
51+
source.should.containEql("function e(){var n=2;n=3,console.log(1+n),console.log(n+3),console.log(4),console.log(1+n+3)}");
52+
});
53+
4754
require.include("./test.js");

test/configCases/plugins/uglifyjs-plugin/webpack.config.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module.exports = {
88
bundle0: ["./index.js"],
99
vendors: ["./vendors.js"],
1010
ie8: ["./ie8.js"],
11-
extract: ["./extract.js"]
11+
extract: ["./extract.js"],
12+
compress: ["./compress.js"]
1213
},
1314
output: {
1415
filename: "[name].js"
@@ -28,5 +29,15 @@ module.exports = {
2829
screw_ie8: false
2930
}
3031
}),
32+
new webpack.optimize.UglifyJsPlugin({
33+
include: ["compress.js"],
34+
compress: {
35+
conditionals: true,
36+
evaluate: true,
37+
passes: 2,
38+
reduce_vars: true,
39+
unused: true
40+
}
41+
}),
3142
]
3243
};

test/statsCases/warnings-uglifyjs/expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Hash: 4beee256fa6b8f69eae8
22
Time: Xms
3-
Asset Size Chunks Chunk Names
4-
bundle.js 2.3 kB 0 [emitted] main
3+
Asset Size Chunks Chunk Names
4+
bundle.js 2.24 kB 0 [emitted] main
55
chunk {0} bundle.js (main) 1.04 kB [entry] [rendered]
66
[0] (webpack)/buildin/module.js 495 bytes {0} [built]
77
[1] (webpack)/test/statsCases/warnings-uglifyjs/a.js 249 bytes {0} [built]

0 commit comments

Comments
 (0)