[英]Loading Require.js Optimized File
I'm using require.js successfully with many separate files: 我成功地将require.js与许多单独的文件配合使用:
require(['app/login/Login'], function (app) {
new app.Login();
});
This all works exactly as expected, with each module loading as required. 所有这些都完全按预期工作,并且按需加载了每个模块。
I've now run my code through the Optimizer and have one combined .js file "everything.js" - which is just what I want. 现在,我已通过优化程序运行代码,并拥有一个组合的.js文件“ everything.js”,这正是我想要的。
But how do I actually load this? 但是我如何实际加载呢?
require(['everything'], function (app) {
new app.Login();
});
Returns me undefined for app
. 返回给我
app
undefined。
Turns out the answer is in the optimizer docs : 原来答案在优化器文档中 :
If you want to include require.js with the main.js source, you can use this kind of command:
如果要在main.js源代码中包含require.js,则可以使用以下命令:
node ../../r.js -o baseUrl=.
节点../../r.js -o baseUrl =。 paths.requireLib=../../require name=main include=requireLib out=main-built.js
path.requireLib = .. / .. / require名称= main include = requireLib out = main-built.js
Since "require" is a reserved dependency name, you create a "requireLib" dependency and map it to the require.js file.
由于“ require”是保留的依赖项名称,因此您将创建“ requireLib”依赖项并将其映射到require.js文件。 Once that optimization is done, you can change the script tag to reference "main-built.js" instead of "require.js", and your optimized project will only need to make one script request.
优化完成后,您可以更改脚本标记以引用“ main-built.js”而不是“ require.js”,并且优化后的项目仅需要发出一个脚本请求。
ie you can change the script tag to reference "main-built.js" instead of "require.js" 即,您可以更改脚本标记以引用“ main-built.js” 而不是 “ require.js”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.