[英]Since r.js compiles AMD modules into one big file, where is the “asynchronous” in Asynchronous Module Definition?
[英]single dependency across multiple modules - r.js “the following module share the same URL”
我已經在多頁面Web應用程序中實現了requirejs,它工作正常,但現在我正在嘗試使用r.js創建一個“所有”模塊的單個文件,除了任何第三方庫和框架,如jquery等...
細分的構建文件(build.js)如下所示:
({
baseUrl: "../",
out: "main-v0.1.js", //"charts-v0.1.js",
include: [
"bi/jquery/jquery.ui.autocomplete",
"bi/jquery/jquery.ui.combobox",
"bi/ui/investmentselector"
],
wrap: true,
exclude: [
'jquery', 'jqueryui', 'jcanvas', 'jqtools', 'prettyphoto', 'cssSandpaper', 'knockout', 'datatables', 'handlebars'
],
preserveLicenseComments: false,
optimize: "none", // "uglify", "uglify2"
paths: {
handlebars : 'lib/handlebars',
/*hb runtime : 'lib/handlebars.runtime',*/
jquery : 'lib/jquery-1.9.1',
jqueryui : 'lib/jquery.ui/jquery-ui-1.10.3.min',
jcanvas : 'lib/jcanvas.min',
jqtools : 'lib/jquery.tools/jquery.tools.min',
prettyphoto : 'lib/jquery/jquery.prettyphoto-3.1.5.min',
BI : 'bi/BI',
sliderconnect : 'bi/charts/slider-connect',
cssSandpaper : 'lib/csssandpaper/cssSandpaper',
csstransform : 'bi/enhance/csstransform',
knockout : 'lib/knockout-2.2.1',
datatables : 'lib/jquery/jquery.dataTables',
// jquery ui widgets
uicombobox : 'bi/jquery/jquery.ui.combobox',
uiautocomplete : 'bi/jquery/jquery.ui.autocomplete'
}
})
jquery.ui.autocomplete.js和jquery.ui.combobox.js文件是自定義jqueryui小部件,沒有任何define()包圍它們。 模塊investmentselector.js(細分)看起來像這樣......
define(['jquery',
'bi/templates/investmentselector.js',
'bi/jquery/datatables/investmentselector.js',
'lib/JSLinq/JSLINQ.js',
'uicombobox', 'uiautocomplete'], function ($, tmp, datatables, jsLinq, uicombobox, uiautocomplete) {
'use strict';
var methods = {
// ... code
};
return methods;
});
當我運行r.js來構建名為'main-v0.1.js'的單個文件時,我得到的是這個......
Tracing dependencies for: D:/Files/Trunk/BestInvest.Select.Website/js/build/main
-v0.1.js
Error: Error: Module loading did not complete for: bi/ui/investmentselector, uic
ombobox, uiautocomplete
The following modules share the same URL. This could be a misconfiguration if th
at URL only has one anonymous module in it:
D:/Files/Trunk/BestInvest.Select.Website/js/bi/jquery/jquery.ui.autocomplete.js:
uiautocomplete, bi/jquery/jquery.ui.autocomplete
D:/Files/Trunk/BestInvest.Select.Website/js/bi/jquery/jquery.ui.combobox.js: uic
ombobox, bi/jquery/jquery.ui.combobox
at Function.build.checkForErrors (D:\Files\Trunk\BestInvest.Select.Website\j
s\build\r.js:27237:19)
關於發生了什么的任何想法?
僅供參考,小部件代碼(再次分解)看起來像這樣......
$.widget("bi.bicombobox", {
_create: function () {
// ...code
},
_destroy: function () { }
});
和...
$.widget("bi.biautocomplete", {
_create: function () {
// ...code
},
_destroy: function () { }
});
任何有關這方面的幫助都會很棒,謝謝!
您的include
選項使用模塊的完整路徑,而不是使用您在paths
建立的縮寫名稱。 使用paths
的名稱:
include: [
"uicombobox",
"uiautocomplete",
"bi/ui/investmentselector"
]
我沒有看到為最后一個定義的另一個名字,所以我原樣離開了它。 通常,您不希望在paths
使用foo: "path/to/foo"
,有時在引用依賴項中的模塊時有時使用foo
path/to/foo
。 你總是想在任何地方使用foo
。 在這里, r.js
看到uicombobox
(舉個例子)並通過paths
解析它的paths
。 它在include
看到"bi/jquery/jquery.ui.combobox"
並通過添加.js
解析它,它指向與第一種情況相同的文件。 然后它意識到它有兩個指向同一文件的模塊,無法處理文件,因為最終文件只需要與一個模塊相關聯。
我還注意到你的define
調用列出了一些帶有.js
擴展名的依賴項。 這違背了未指定擴展名的建議做法。 有時延伸,有時不延伸,可能會引起像我上面所解釋的那樣的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.