上下文如下:
Main file called start.js is:
require([/* some stuff */], function (){ /* app logic */ });
which has an if that decides what I should require based on some condition.
The required files are either ModuleA or ModuleB
Both ModuleA and ModuleB have dependencies.
define([/*some deps*/], function(dep1, dep2...) { /* app logic */ return { /* interface */ }
Everything works fine in development mode, before optimization and module concatenation.
When building with r.js I specify as module targets the following : modules : [ { name : "start" }, { name : "ModuleA" }, { name : "ModuleB" } ]
define(dep1 ..);
define(dep2 ..);
define(ModuleA ..);
但是ModuleA中没有加载任何内容。在开发时,ModuleA的代码可以加载和执行,但构建后的代码无法运行。
我该如何解决这个问题?
更新 http://pastebin.com/p1xUcY0A --> start.js http://pastebin.com/dXa6PtpX --> ModuleA js-animation.js http://pastebin.com/xcCvhLrT --> ModuleB css-animation.js无依赖项。 http://pastebin.com/j51V5kMt --> 运行优化器时使用的r.js配置文件。
http://pastebin.com/UVkWjwe9 --> 运行 r.js 后的 js-animation.js 文件。这个文件存在问题。我没有从这个文件中获取到 js-animation 模块。require 不会返回我的 js-animation 对象。
编辑:
在模块定义和开始 js 中去掉末尾的 .js 后,优化后的 start.js 是 http://pastebin.com/LfaLkJaT,js-animations 模块是 http://pastebin.com/qwnpkCC6。在 Chrome 中,我的控制台显示了这个错误http://pastebin.com/Hq7HGcmm。
require
之外还有其他逻辑吗?如果是这样,这个数组会包含依赖项名称“ModuleA”或“ModuleB”吗?也许你可以添加start.js
的代码... - rharper