javascript - 将javascript模块集成到一个文件中进行部署的方法?

标签 javascript module integration loading code-organization

在开发方面,我使用 JS 模块来更好地组织我的代码。例如,我有 module1.jsmodule2.js,这两个模块都包含在带有 LABjsmain.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.jstwo.js三.js:

要求([“一”,“二”,“三”],功能(一,二,三){ });

这个优化工具可以将它们压缩成一个完整的文件是

node ../../r.js -o name=main out=main-built.js baseUrl=.

关于javascript - 将javascript模块集成到一个文件中进行部署的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8113142/

相关文章:

R:如何计算截断正态分布的均值和协方差

javascript - 通过 JQuery 和 JavaScript 函数提交按钮所做的更改不会持续

javascript - 为什么javascript :void(0) is not working in Firefox

R Shiny 的 observeEvent 在模块中不起作用

java - 自定义 Android 模块中的重复条目 : org/appcelerator/titanium/gen/bindings. json

c++ - 将 MySQL 与 C++ 集成的简单解决方案?

iOS : Where to start for AliPay integration?

javascript - 在 jQuery.extend() 中使用 $(this)

javascript - jquery 使用什么 javascript min 工具?

python - 安装 python reddit api 包装器模块