javascript - Dojo 构建如何缩小用 ECMASCRIPT5 编写的代码?

标签 javascript batch-file dojo google-closure-compiler

我正在使用 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

https://bugs.dojotoolkit.org/ticket/16601

关于javascript - Dojo 构建如何缩小用 ECMASCRIPT5 编写的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33936204/

相关文章:

batch-file - 为什么我既不能批量也不能在cmd中调用 “IF”和 “FOR”?

javascript - 使用带有 FixSplitter 的 Dojo 会产生不需要的结果

javascript - Chrome 中的并发 Ajax 请求

javascript - 动态否定外部脚本

java - 如何在执行运行时命令后停止 java 挂起

javascript - Dijit 对话框按钮事件未执行

javascript - 从数组中的文件中读取行

javascript - 删除 json 对象键值对中的空格

javascript - HTML5 Canvas 的调整大小功能

batch-file - MS-DOS内置命令是否返回错误\退出代码?