【发布时间】:2014-02-12 17:19:37
【问题描述】:
我有一个不错的 require.js + r.js 设置。现在,我似乎在这两者之间有一个“一个或另一个”的选择:
- 使用 name + out 选项只创建一个 js 文件,没有别的
- 使用 appDir + dir 选项将所有文件从 appDir 复制到目录
第二个选项是我目前使用的。然而,这将复制和缩小许多实际包含在我编译的 main.js 中的文件。这些文件永远不会真正加载。
r.js 是否有一些选项可以跳过属于缩小过程的文件?
插图
假设我在appDir 中有这些文件:
index.html
main.js
lib/
- libA.js (dependency of main, will be loaded by require.js)
- libB.js (dependency of main, will be loaded by require.js)
- libC.js (loaded any other way)
img/
- imgA.png
- imgB.png
第一个选项(name+out)只会产生一个巨大的丑化main.js。
main.js
第二个选项 (appDir+dir) 将在 dir/ 中创建类似这样的内容
index.html
main.js (uglified)
lib/
- libA.js (uglified and will never be loaded)
- libB.js (uglified and will never be loaded)
- libC.js (uglified and used)
img/
- imgA.png
- imgB.png
我真正喜欢的是这样的:
index.html
main.js
lib/
- libC.js (no libA.js / libB.js)
img/
- imgA.png
- imgB.png
(所以无论如何都没有包含在 main.js 中的库)。
【问题讨论】:
标签: javascript requirejs r.js