Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
Print Culprit File when UglifyJS Fails
Browse files Browse the repository at this point in the history
UglifyJS can fail for good reasons such as:
1. Static checker found bad codes (i.e. unclosed parenthesis)
2. ES6 is used in browser asset JS.

Printing the file name helps with debugging.
  • Loading branch information
dharijanto committed Oct 24, 2017
1 parent 1a67f2b commit a34d488
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/main.js
Expand Up @@ -202,13 +202,20 @@ var compile = function(fileName, assets, S3, options, method, type, timestamp, c
case 'uglify':
if (results instanceof Array)
results = results.join("\n");
var final_code = uglify.minify(results, {
fromString: true,
output: {
comments: /license/
}
}).code;
pushFileToS3(S3, final_code, fileName, headers, callback);
try {
var final_code = uglify.minify(results, {
fromString: true,
output: {
comments: /license/
}
}).code;
pushFileToS3(S3, final_code, fileName, headers, callback);
} catch(err) {
logger({
task: 'express-cdn',
message: 'Failed to minify ' + fileName + ' due to uglify-js error.'})
throw err
}
break;
case 'minify':
if (!(results instanceof Array)) {
Expand Down

0 comments on commit a34d488

Please sign in to comment.