我遇到了完全相同的问题,在阅读了大量的dojo文档和源代码后,我得出结论:如果几乎不可能做到这一点非常困难。然而,有一个非常简单和优雅的解决方法。不过,告诉你如何首先解决的问题,为什么没有在第一位置需要一个解决办法之前(这样你就可以调整解决你自己的情况):
第一个问题,资源是不可发现
根据道场构建系统Reference Guide的概述部分:
[The build system] “discovers” a set of resources and then applies a synchronized, ordered set of resource-dependent transforms to those resources. (…) When a resource is discovered, it is tagged with one or more flags that help identify the role of that resource. (…) After a resource is discovered and tagged, the system assigns a set of transforms that are to be applied to that resource.
因此,在短期,在飞行中产生的任何资源不能由生成系统发现的,因为他们不驻留在文件系统上。如果它们不能被发现,那么它们不能被标记,也不能对其应用变换。特别是,resourceTags
不会被调用这些资源,您不能将它们放在配置文件图层定义的exclude
列表中(比较部分Creating Builds中的层)。
顺便说一句,据我明白documentation to depsScan transform,internStringsSkipList
只能用于跳过资源指定使用传统的符号(dojo.something
,例如dojo.moduleUrl
)。
第二个问题,插件解析器需要一个物理文件
符号dojo/text!/some/url
表示使用dojo/text.js
组件作为一个插件。我发现这个音符this ticket:
Every AMD plugin should have a plugin resolver in util/build/plugins
and have it registered in util/build/buildControlDefault
.
如果检查util/build/plugins/text.js
(如on Github),你会看到,被抛出的错误,因为依赖(dojo/text!
后一部分被存储在moduleInfo
)是不是在resources
array:
textResource = bc.resources[moduleInfo.url];
if (!textResource){
throw new Error("text resource (" + moduleInfo.url + ") missing");
}
而这正是因为在“发现”阶段无法发现资源。
困难的解决方案
在困难的解决方案,可能会或可能无法正常工作,你需要改变如何转型depsScan
作品。基本上,当depsScan
遇到dojo/text!/some/url
它调用插件解析器来检查依赖项是否存在。从depsScan documentation:
Once all dependencies are found, the transform ensures all dependencies exist in the discovered modules. Missing dependencies result in an error being logged to the console and the build report.
这可能是通过重新定义transformJobs
包含自定义转换为depsScan
可能。有关更多见解,请参阅util/build/buildControlDefault.js
(on Github)和this forum post。
的简单的解决方法
只需创建自己的插件加载资源。自己的插件将没有注册的插件解析器(见上面的第二个问题)和所有编译时,你会得到的是可怕的
warn(224) A plugin dependency was encountered but there was no build-time plugin resolver.
这是我这样的插件的例子加载一个JSON资源动态:
define(["dojo/text", "dojo/_base/lang", "dojo/json"],
function(text,lang,json){
return lang.delegate(text, {
load: function(id, require, load){
text.load(id, require, function(data){
load(json.parse(data));
});
}
});
});
它重新使用dojo/text
添加其自定义加载功能。这是发布在this dojo-toolkit forum post上的另一个例子的改编。您可以在JSFiddle上看到他们的代码。
在项目中,我使用这样的插件:
define(["./json!/path/to/an/json"],
function(values){
return values;
});
你的插件可以只返回加载的模板而不解析它作为JSON,只要你不指定自定义插件解析器(其中将期望文件在磁盘上物理存在)项目将编译好。
Amiramix,我有同样的问题,我努力遵循你的答案。你介意我是否直接与你联系? – 2014-03-26 16:08:44
当然,在我的个人资料中,你可以找到我的个人网站,在那里你可以看到我的电子邮件(除非你想用其他方式与我联系?)。 – Amiramix 2014-03-27 00:44:12