Skip to content

Commit 6a9bd13

Browse files
committed
better minimize options and error handling
1 parent 4656133 commit 6a9bd13

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

lib/webpack.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -554,17 +554,20 @@ getTemplate.chunk = function(chunk, options, templateOptions) {
554554

555555
// minimize it the uglify
556556
function uglify(input, filename, options) {
557-
if(typeof options != "object") options = {
558-
warnings: false
559-
};
557+
if(typeof options != "object") options = {};
558+
if(typeof options.compressor == "undefined") {
559+
options.compressor = {
560+
warnings: false
561+
}
562+
}
560563
var uglify2 = require("uglify-js2");
561564
try {
562565
var ast = uglify2.parse(input, {
563566
filename: filename
564567
});
565568
ast.figure_out_scope()
566-
if(options.compress !== false) {
567-
var compressor = uglify2.Compressor(options);
569+
if(options.compressor !== false) {
570+
var compressor = uglify2.Compressor(options.compressor);
568571
ast = ast.transform(compressor);
569572
ast.figure_out_scope();
570573
ast.compute_char_frequency(options.mangle || {});
@@ -574,9 +577,10 @@ function uglify(input, filename, options) {
574577
comments: options.comments || /^\**!|@preserve|@license/,
575578
beautify: options.beautify
576579
});
580+
return source;
577581
} catch(e) {
578-
throw new Error(filename + " @ Line " + e.line + ", Col " + e.col + ", " + e);
582+
console.warn(e.msg || e.message || (e + ""));
583+
console.warn(" @ " + filename);
579584
return input;
580585
}
581-
return source;
582586
}

lib/writeSource.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,20 @@ module.exports = function(module, options, toRealId, toRealChuckId) {
322322

323323
// minimize it the uglify
324324
function uglify(input, filename, options, beautify) {
325-
if(typeof options != "object") options = {
326-
warnings: false
327-
};
325+
if(typeof options != "object") options = {};
326+
if(typeof options.compressor == "undefined") {
327+
options.compressor = {
328+
warnings: false
329+
}
330+
}
328331
var uglify2 = require("uglify-js2");
329332
try {
330333
var ast = uglify2.parse(input, {
331334
filename: filename
332335
});
333336
ast.figure_out_scope()
334-
if(options.compress !== false) {
335-
var compressor = uglify2.Compressor(options);
337+
if(options.compressor !== false) {
338+
var compressor = uglify2.Compressor(options.compressor);
336339
ast = ast.transform(compressor);
337340
ast.figure_out_scope();
338341
ast.compute_char_frequency(options.mangle || {});
@@ -342,9 +345,10 @@ function uglify(input, filename, options, beautify) {
342345
comments: options.comments || /^\**!|@preserve|@license/,
343346
beautify: beautify
344347
});
348+
return source;
345349
} catch(e) {
346-
throw new Error(filename + " @ Line " + e.line + ", Col " + e.col + ", " + e);
350+
console.warn(e.msg || e.message || (e + ""));
351+
console.warn(" @ " + filename);
347352
return input;
348353
}
349-
return source;
350354
}

0 commit comments

Comments
 (0)