我遇到了完全相同的問題,在閱讀了大量的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