Skip to content

Commit 4024689

Browse files
committed
Stronger check and override of comments in UglifyJsPlugin options
Fixes webpack#324
1 parent c4d78f7 commit 4024689

5 files changed

Lines changed: 62 additions & 1 deletion

File tree

lib/optimize/UglifyJsPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
9292
ast.mangle_names(options.mangle || {});
9393
}
9494
var output = {};
95-
output.comments = options.comments || /^\**!|@preserve|@license/;
95+
output.comments = Object.prototype.hasOwnProperty.call(options, "comments") ? options.comments : /^\**!|@preserve|@license/;
9696
output.beautify = options.beautify;
9797
for(var k in options.output) {
9898
output[k] = options.output[k];
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
it("should contain no comments in out chunk", function() {
2+
var fs = require("fs");
3+
var source = fs.readFileSync(__filename, "utf-8");
4+
source.should.not.match(/[^\"]comment should be stripped test\.1[^\"]/);
5+
source.should.not.match(/[^\"]comment should be stripped test\.2[^\"]/);
6+
source.should.not.match(/[^\"]comment should be stripped test\.3[^\"]/);
7+
});
8+
9+
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");
13+
source.should.containEql("comment should not be stripped vendors.1");
14+
source.should.containEql("// comment should not be stripped vendors.2");
15+
source.should.containEql(" * comment should not be stripped vendors.3");
16+
});
17+
18+
19+
require.include("./test.js");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @preserve comment should be stripped test.1 */
2+
3+
var foo = {};
4+
5+
// comment should be stripped test.2
6+
7+
/**
8+
* comment should be stripped test.3
9+
*/
10+
11+
module.exports = foo;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @preserve comment should not be stripped vendors.1 */
2+
3+
var bar = {};
4+
5+
// comment should not be stripped vendors.2
6+
7+
/**
8+
* comment should not be stripped vendors.3
9+
*/
10+
11+
module.exports = bar;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var webpack = require("../../../../");
2+
module.exports = {
3+
node: {
4+
__dirname: false,
5+
__filename: false
6+
},
7+
entry: {
8+
bundle0: ["./index.js"],
9+
vendors: ["./vendors.js"]
10+
},
11+
output: {
12+
filename: "[name].js"
13+
},
14+
plugins: [
15+
new webpack.optimize.UglifyJsPlugin({
16+
comments: false,
17+
exclude: ["vendors.js"]
18+
})
19+
]
20+
};

0 commit comments

Comments
 (0)