Skip to content

Commit 9e7ab60

Browse files
committed
Relates to #959, document ES5 limitation on included uglifyjs
1 parent c1a1415 commit 9e7ab60

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

build/example.build.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,24 @@
9898
//will be included in a build layer regardless of locale being set.
9999
locale: "en-us",
100100

101-
//How to optimize all the JS files in the build output directory.
101+
//How to optimize (minify) all the JS files in the build output directory.
102102
//Right now only the following values
103103
//are supported:
104104
//- "uglify": (default) uses UglifyJS to minify the code. Before version
105105
//2.2, the uglify version was a 1.3.x release. With r.js 2.2, it is now
106-
//a 2.x uglify release.
106+
//a 2.x uglify release. Only supports ES5 syntax. For ES 2015 or later, use
107+
//the "none" option instead.
107108
//- "uglify2": in version 2.1.2+. Uses UglifyJS2. As of r.js 2.2, this
108109
//is just an alias for "uglify" now that 2.2 just uses uglify 2.x.
109110
//- "closure": uses Google's Closure Compiler in simple optimization
110111
//mode to minify the code. Only available if running the optimizer using
111112
//Java.
112113
//- "closure.keepLines": Same as closure option, but keeps line returns
113114
//in the minified files.
114-
//- "none": no minification will be done.
115+
//- "none": no minification will be done. Use this setting if you are using
116+
//ES 2015 or later syntax in your files, since the bundled UglifyJS only
117+
//understands ES5 and earlier syntax. For ES2015 code, run a compliant
118+
// minifier as a separate step after running r.js.
115119
optimize: "uglify",
116120

117121
//Introduced in 2.1.2: If using "dir" for an output directory, normally the

build/jslib/optimize.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ function (lang, logger, envOptimize, file, parse,
1515
cssUrlRegExp = /\url\(\s*([^\)]+)\s*\)?/g,
1616
protocolRegExp = /^\w+:/,
1717
SourceMapGenerator = sourceMap.SourceMapGenerator,
18-
SourceMapConsumer =sourceMap.SourceMapConsumer;
18+
SourceMapConsumer = sourceMap.SourceMapConsumer,
19+
es5PlusGuidance = 'If the source uses ES2015 or later syntax, please pass "optimize: \'none\'" to r.js and use an ES2015+ compatible minifier after running r.js. The included UglifyJS only understands ES5 or earlier syntax.';
1920

2021
/**
2122
* If an URL from a CSS url value contains start/end quotes, remove them.
@@ -458,7 +459,11 @@ function (lang, logger, envOptimize, file, parse,
458459
fileContents = result.code;
459460
}
460461
} catch (e) {
461-
throw new Error('Cannot uglify file: ' + fileName + '. Skipping it. Error is:\n' + e.toString());
462+
var errorString = e.toString();
463+
var isSyntaxError = /SyntaxError/.test(errorString);
464+
throw new Error('Cannot uglify file: ' + fileName +
465+
'. Skipping it. Error is:\n' + errorString +
466+
(isSyntaxError ? '\n\n' + es5PlusGuidance : ''));
462467
}
463468
return fileContents;
464469
}

0 commit comments

Comments
 (0)