diff --git a/lib/uglifier.js b/lib/uglifier.js index 7e759c6..29f06f4 100644 --- a/lib/uglifier.js +++ b/lib/uglifier.js @@ -101,7 +101,8 @@ function processAssets(compilation, options) { } }) .catch((e) => { - compilation.errors.push(new Error(`minifying ${assetName}\n${e}`)); + const builtError = new Error(`Encountered an error while minifying ${assetName}:\n${e}`); + compilation.errors.push(builtError); }); }); diff --git a/lib/worker.js b/lib/worker.js index db432ba..64e9e94 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -1,3 +1,4 @@ +const codeFrame = require('babel-code-frame'); const cache = require('./cache'); const tmpFile = require('./tmp-file'); const BOGUS_SOURCEMAP_STRING = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; @@ -20,7 +21,16 @@ function minify(source, map, uglifyOptions, uglifier) { } const result = uglifier.minify(source, opts); - if (result.error) throw result.error; + if (result.error) { + if (result.error.name === 'SyntaxError') { + const frame = codeFrame(source, result.error.line, result.error.col); + const errorMessage = `${result.error.name}: ${result.error.message}\n${frame}`; + throw new SyntaxError(errorMessage); + } + + throw result.error; + } + result.code = result.code.replace(new RegExp(BOGUS_SOURCEMAP_URL), ''); return result; diff --git a/package.json b/package.json index 65e0e8a..0f63377 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "webpack": "^3.0.0" }, "dependencies": { + "babel-code-frame": "^6.26.0", "glob": "^7.0.5", "mkdirp": "^0.5.1", "pify": "^3.0.0",