在开发中,我使用JS模块来更好地组织代码。例如,我有module1.jsmodule2.js,两个模块都包含在LABjs中,并带有documentation

$LAB
.script("module1.js").wait()
.script("module2.js").wait();

但是,我也使用Google Closure Compiler进行代码优化,根据ojit_a,它需要一个集成的javascript文件。



因此,我想将所有模块集成到一个js文件中,然后可以使用Google Closure Compiler进行编译。 LabJS在客户端运行,不会在服务器端完成工作。那么,有什么工具可以完成这项工作吗?还是有其他库支持服务器端模块集成?

最佳答案

我发现RequireJS提供了一个优化工具,可以



在文档中,对于包含以下main.js的页面,该页面导入one.jstwo.jsthree.js:
require(["one", "two", "three"], function (one, two, three) {});
该优化工具可以将它们压缩到一个集成文件中
node ../../r.js -o name=main out=main-built.js baseUrl=.

09-20 12:08