Skip to content

Commit 7b9eb0c

Browse files
test(configCases/uglifyjs-plugin): update to new options interface (options.uglifyOptions)
1 parent 21945f8 commit 7b9eb0c

File tree

5 files changed

+267
-263
lines changed

5 files changed

+267
-263
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"source-map": "^0.5.3",
2222
"supports-color": "^4.2.1",
2323
"tapable": "^0.2.8",
24-
"uglifyjs-webpack-plugin": "^1.0.0",
24+
"uglifyjs-webpack-plugin": "^1.1.1",
2525
"watchpack": "^1.4.0",
2626
"webpack-sources": "^1.0.1",
2727
"yargs": "^8.0.2"

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
/** @preserve comment should be extracted extract-test.1 */
2-
31
var foo = {};
42

3+
// ⚠️ move the following comment back to the top
4+
// https://github.com/mishoo/UglifyJS2/issues/2500
5+
/** @preserve comment should be extracted extract-test.1 */
6+
57
// comment should be stripped extract-test.2
68

79
/*!
Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,65 @@
1-
it("should contain no comments in out chunk", function() {
2-
var fs = require("fs");
3-
var source = fs.readFileSync(__filename, "utf-8");
1+
it("should contain no comments in out chunk", () => {
2+
const fs = require("fs");
3+
4+
const source = fs.readFileSync(__filename, "utf-8");
5+
46
source.should.not.match(/[^\"]comment should be stripped test\.1[^\"]/);
57
source.should.not.match(/[^\"]comment should be stripped test\.2[^\"]/);
68
source.should.not.match(/[^\"]comment should be stripped test\.3[^\"]/);
79
});
810

911
it("should contain comments in vendors chunk", function() {
10-
var fs = require("fs"),
11-
path = require("path");
12-
var source = fs.readFileSync(path.join(__dirname, "vendors.js"), "utf-8");
12+
const fs = require("fs");
13+
const path = require("path");
14+
15+
const source = fs.readFileSync(path.join(__dirname, "vendors.js"), "utf-8");
16+
1317
source.should.containEql("comment should not be stripped vendors.1");
1418
source.should.containEql("// comment should not be stripped vendors.2");
1519
source.should.containEql(" * comment should not be stripped vendors.3");
1620
});
1721

18-
// this test is based off https://github.com/mishoo/UglifyJS2/blob/master/test/compress/screw-ie8.js
19-
it("should pass mangle options", function() {
20-
var fs = require("fs"),
21-
path = require("path");
22-
var source = fs.readFileSync(path.join(__dirname, "ie8.js"), "utf-8");
23-
source.should.containEql("function r(t){return function(n){try{t()}catch(t){n(t)}}}");
24-
});
25-
2622
it("should extract comments to separate file", function() {
27-
var fs = require("fs"),
28-
path = require("path");
29-
var source = fs.readFileSync(path.join(__dirname, "extract.js.LICENSE"), "utf-8");
23+
const fs = require("fs");
24+
const path = require("path");
25+
26+
const source = fs.readFileSync(path.join(__dirname, "extract.js.LICENSE"), "utf-8");
27+
3028
source.should.containEql("comment should be extracted extract-test.1");
3129
source.should.not.containEql("comment should be stripped extract-test.2");
3230
source.should.containEql("comment should be extracted extract-test.3");
3331
source.should.not.containEql("comment should be stripped extract-test.4");
3432
});
3533

3634
it("should remove extracted comments and insert a banner", function() {
37-
var fs = require("fs"),
38-
path = require("path");
39-
var source = fs.readFileSync(path.join(__dirname, "extract.js"), "utf-8");
35+
const fs = require("fs");
36+
const path = require("path");
37+
38+
const source = fs.readFileSync(path.join(__dirname, "extract.js"), "utf-8");
39+
4040
source.should.not.containEql("comment should be extracted extract-test.1");
4141
source.should.not.containEql("comment should be stripped extract-test.2");
4242
source.should.not.containEql("comment should be extracted extract-test.3");
4343
source.should.not.containEql("comment should be stripped extract-test.4");
4444
source.should.containEql("/*! For license information please see extract.js.LICENSE */");
4545
});
4646

47+
it("should pass mangle options", function() {
48+
const fs = require("fs");
49+
const path = require("path");
50+
51+
const source = fs.readFileSync(path.join(__dirname, "ie8.js"), "utf-8");
52+
53+
source.should.containEql("t.exports=function(t){return function(n){try{t()}catch(t){n(t)}}}");
54+
});
55+
4756
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 o=2;o=3,console.log(1+o),console.log(o+3),console.log(4),console.log(1+o+3)}");
57+
const fs = require("fs");
58+
const path = require("path");
59+
60+
const source = fs.readFileSync(path.join(__dirname, "compress.js"), "utf-8");
61+
62+
source.should.containEql("o.exports=function(){console.log(4),console.log(6),console.log(4),console.log(7)}");
5263
});
5364

5465
require.include("./test.js");
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
var webpack = require("../../../../");
1+
const webpack = require("../../../../");
2+
23
module.exports = {
34
node: {
45
__dirname: false,
56
__filename: false
67
},
78
entry: {
9+
ie8: ["./ie8.js"],
810
bundle0: ["./index.js"],
911
vendors: ["./vendors.js"],
10-
ie8: ["./ie8.js"],
1112
extract: ["./extract.js"],
1213
compress: ["./compress.js"]
1314
},
@@ -16,28 +17,26 @@ module.exports = {
1617
},
1718
plugins: [
1819
new webpack.optimize.UglifyJsPlugin({
19-
comments: false,
20-
exclude: ["vendors.js", "extract.js"],
21-
mangle: {
22-
screw_ie8: false
23-
}
20+
exclude: [
21+
"vendors.js",
22+
"extract.js"
23+
]
2424
}),
2525
new webpack.optimize.UglifyJsPlugin({
2626
extractComments: true,
27-
include: ["extract.js"],
28-
mangle: {
29-
screw_ie8: false
30-
}
27+
include: [
28+
"extract.js"
29+
]
3130
}),
3231
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-
}),
32+
uglifyOptions: {
33+
compress: {
34+
passes: 2
35+
}
36+
},
37+
include: [
38+
"compress.js"
39+
]
40+
})
4241
]
4342
};

0 commit comments

Comments
 (0)