在开发方面,我使用 JS 模块来更好地组织我的代码。例如,我有 module1.js
、module2.js
,这两个模块都包含在带有 LABjs 的 main.js
中。
$LAB
.script("module1.js").wait()
.script("module2.js").wait();
但是,我也使用 Google Closure Compiler 进行代码优化,它需要根据 documentation 集成的 javascript 文件。 .
The simplest solution to this problem is to compile your functions together with the portion of your program that calls those functions.
所以我想将所有模块集成到一个 js 文件中,然后可以使用 Google Closure Compiler 对其进行编译。 LabJS 在客户端运行,不会在服务器端完成任务。那么有什么工具可以完成这项工作吗?或者是否有其他库支持服务器端模块集成?
最佳答案
我找到了 RequireJS提供了一个优化工具,可以
Combines related scripts together into build layers and minifies them via UglifyJS (the default) or Closure Compiler (an option when using Java).
在文档中,对于具有以下 main.js
的页面,它导入了 one.js
、two.js
和 三.js
:
要求([“一”,“二”,“三”],功能(一,二,三){
});
这个优化工具可以将它们压缩成一个完整的文件是
node ../../r.js -o name=main out=main-built.js baseUrl=.
关于javascript - 将javascript模块集成到一个文件中进行部署的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8113142/