我正在使用 dojo build tools为了缩小我的项目。
我的部分代码是使用 ECMASCRIPT5
编写的,在运行 standard .bat file 时,我从 Closure Compiler 收到错误消息.
似乎它们是一些限制,因为默认情况下编译器在 ES3 上设置为 described here .
0 error(s), 1 warning(s)
builderReference.js.uncompressed.js:15: ERROR - Parse error. getters are not supported in older versions of JS. If you are targeti
ng newer versions of JS, set the appropriate language_in option.
get builder() {
^
我需要能够编译我的 ES5 代码,我更改了 .bat 文件
试图传递标志 language_in=ECMASCRIPT5
java -Xms256m -Xmx256m -cp "%~dp0../shrinksafe/js.jar";"%~dp0../closureCompiler/compiler.jar";"%~dp0../shrinksafe/shrinksafe.jar" org.mozilla.javascript.tools.shell.Main "%~dp0../../dojo/dojo.js" baseUrl="%~dp0../../dojo" load=build language_in=ECMASCRIPT5 %*
不幸的是,我仍然收到同样的错误。
我需要知道:
- 如何缩小用 ES5 编写的代码?
.bat 文件
中的标志是否正确?- 是否可以在xxx.profile.js中加入这个配置?
非常欢迎任何想法,谢谢。
最佳答案
在app.profile.js
中添加如下配置即可解决问题。
// Set the optimization options for the Google closure compiler.
optimizeOptions: {
languageIn: Packages.com.google.javascript.jscomp.CompilerOptions.LanguageMode.ECMASCRIPT5
}
来自 dojo 文档:
optimizeOptions (default = "undefined") This object is passed to the JavaScript optimizer to allow for compiler specific settings. Settings for UglifyJS and closure compiler can be set using this object.
不幸的是,文档没有提供该对象的详细信息。下面是一些包含更多资源的链接:
http://dojo-toolkit.33424.n3.nabble.com/Build-Pass-options-to-Closure-compiler-td4002152.html
http://dojotoolkit.org/reference-guide/1.10/build/qref.html
https://groups.google.com/forum/#!msg/requirejs/9f4sgewYnAw/G-oSqCz2DSEJ
https://bugs.dojotoolkit.org/ticket/16196
https://github.com/dojo/util/pull/27
http://dojo-toolkit.33424.n3.nabble.com/Build-Pass-options-to-Closure-compiler-td4002152.html
关于javascript - Dojo 构建如何缩小用 ECMASCRIPT5 编写的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33936204/