Javascript WIKI:如何使用Lime(如何将闭包编译器与第三方(闭包)库一起使用)
下面的帖子启发了我去看看limeJS,作为一个辅助项目,我正在做一个Yatzee游戏(大部分是关闭的),并认为这可能是一个很好的库使用 作为谷歌闭包的初学者,我在运行未编译代码和编译代码时遇到了一些困难,主要是因为不知道选项和命令是什么,以及依赖关系 对于其他使用google closuse的初学者,我编写了本教程 请注意,jQuery可以由闭包编译代码使用,但您需要jQuery。您不能将jQuery编译到代码中,闭包库有一个经过修饰的dojo,可以在第三方中找到。使用它时,您可以将代码编译成一个文件 您需要的:Javascript WIKI:如何使用Lime(如何将闭包编译器与第三方(闭包)库一起使用),javascript,dependencies,google-closure-compiler,google-closure-library,limejs,Javascript,Dependencies,Google Closure Compiler,Google Closure Library,Limejs,下面的帖子启发了我去看看limeJS,作为一个辅助项目,我正在做一个Yatzee游戏(大部分是关闭的),并认为这可能是一个很好的库使用 作为谷歌闭包的初学者,我在运行未编译代码和编译代码时遇到了一些困难,主要是因为不知道选项和命令是什么,以及依赖关系 对于其他使用google closuse的初学者,我编写了本教程 请注意,jQuery可以由闭包编译代码使用,但您需要jQuery。您不能将jQuery编译到代码中,闭包库有一个经过修饰的dojo,可以在第三方中找到。使用它时,您可以将代码编译成一
- D:
- 计划
- 图书馆
- 傻瓜
- 石灰
- 动画
- 音频
- css
- 第三方
- 关闭
- 关闭
- 圆球
- 资产
- 。。。其他圆球的东西
- 图书馆
- 计划
<script type="text/javascript" src="../../../closure/closure/goog/base.js"></script>
未编译的代码使用/goog/deps.js加载依赖项。caclcdeps.py将检查以rb.js开头的代码(因为这是代码的起点),并根据项目使用的内容向deps.js添加条目
同样,可以在closure库的bin目录中找到cacldeps.py
请注意,当您有另一个项目时;假设D:\projects\project2,那么您必须在该项目目录中创建一个makedeps.bat,该目录为您重新创建deps.js,然后才能运行未编译的代码。这是因为多个项目共享一个google闭包库,所以在切换项目时,请确保在运行未编译代码之前先构建deps.js
解决缺少的依赖项
打开rt.html仍然会出现一个错误,但有一个不同的错误:错误:“未定义lame.css的nameToPath”
查看goog/deps.js,我们可以发现lime需要lime.css,但在deps.js中没有条目。为什么会这样?在D:\projects\libraries\lime中查找时,没有css目录或css.js文件。但是在您克隆git项目的目录中有一个名为css的目录
将css目录复制到D:\projects\libraries\lime并再次运行makedeps.bat,现在当您打开rt.html时,它将运行
整个过程是未编译的,您可以设置断点以进入第三方代码
编译你的代码
在生产中,您可能希望将代码编译为一个文件。为了编译代码,我在D:\projects\roundball中创建了一个compile.bat,包含以下内容:
set calc="D:\software\closure compiler\library\closure\bin\calcdeps.py"
c:\Python27\python.exe %calc% ^
--path D:\projects\roundball\ ^
--path D:\projects\libraries\ ^
--input D:\projects\roundball\rb.js ^
--output_mode deps ^
--output_file D:\projects\libraries\goog\deps.js
pause
set calc="D:\software\closure compiler\library\closure\bin\calcdeps.py"
c:\Python27\python.exe %calc% ^
--path D:\projects\roundball\ ^
--path D:\projects\libraries\ ^
--input D:\projects\roundball\rb.js ^
--compiler_jar "D:\software\closure compiler\compiler.jar" ^
--output_mode compiled ^
--compiler_flags="--compilation_level=ADVANCED_OPTIMIZATIONS" ^
--compiler_flags="--formatting=PRETTY_PRINT" ^
--output_file D:\projects\roundball\compiled\roundball.js
pause
;Need this flag for production compile:
;--compiler_flags="--define goog.DEBUG=false" ^
;Remove the following flag from production compile:
;--compiler_flags="--formatting=PRETTY_PRINT" ^
;lime libraries is giving me errors with stricter compilation
; so had to remove this flag (have to fix the errors or no type checking for your code)
;--compiler_flags="--warning_level=VERBOSE" ^
文件compiler.jar可以在下载(并提取)闭包编译器的地方找到
现在,当您运行compile.bat并打开D:\projects\roundball\compiled\roundball.html时,您将在浏览器的开发工具中看到只有roundball.js被加载。答案在问题中,因为这是一篇howto文章,可以帮助某些人(比如将来我忘记如何做时)
set calc="D:\software\closure compiler\library\closure\bin\calcdeps.py"
c:\Python27\python.exe %calc% ^
--path D:\projects\roundball\ ^
--path D:\projects\libraries\ ^
--input D:\projects\roundball\rb.js ^
--compiler_jar "D:\software\closure compiler\compiler.jar" ^
--output_mode compiled ^
--compiler_flags="--compilation_level=ADVANCED_OPTIMIZATIONS" ^
--compiler_flags="--formatting=PRETTY_PRINT" ^
--output_file D:\projects\roundball\compiled\roundball.js
pause
;Need this flag for production compile:
;--compiler_flags="--define goog.DEBUG=false" ^
;Remove the following flag from production compile:
;--compiler_flags="--formatting=PRETTY_PRINT" ^
;lime libraries is giving me errors with stricter compilation
; so had to remove this flag (have to fix the errors or no type checking for your code)
;--compiler_flags="--warning_level=VERBOSE" ^