如何将所有文件包含在 dojo 构建层中?
How to include all files in dojo build layer?
我有一个这样定义的配置文件:
var profile = {
....
layers: {
"dojo/dojo": {
include: ["dojo/main" ],
customBase: true,
boot: true
}
, "my/widget": { include: [
"my/widget/AuthorWidget",
"my/widget/templates/AuthorWidget.html" ]
}
},
....
}
这就是我想要的。它创建文件 dojo.js 和 widget.js,其中包含我需要的所有内容。
有没有更好的方法来包含来自 my/widget 的所有文件而不将它们列在 include: 中? AuthorWidget.js 看起来像这样:
define([
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dojo/text!./templates/AuthorWidget.html",
"dojo/dom-style",
....
所以我希望包括来自 my/widget/templates/AuthorWidget.html 的每个相关小部件。不幸的是,我在 include: 数组中有这个文件,否则 dijig/form/Button 不会包含在结果中。 (我有 [button type="button" data-dojo-type="dijit/form/Button"]Click Me![/button] 在 AuthorWidget.html)
my.profile.js:
var profile = (function(){
return {
basePath: "./src",
releaseDir: "../release",
releaseName: "my",
action: "release",
defaultConfig: {
async: 1
},
packages:[{
name: "dojo",
location: "dojo"
},{
name: "dijit",
location: "dijit"
},{
name: "dojox",
location: "dojox"
},{
name: "my",
location: "../js/my",
destLocation: "myapp"
}],
layers: {
"dojo/dojo": {
include: ["dojo/main" ],
customBase: true,
boot: true
}
//this works
//, "my/widget": { include: [ "my/widget/AuthorWidget", "my/widget/templates/AuthorWidget.html" ] }
//this doesnt include Button widget required by AuthorWidget.html
, "my/widget": { include: [ "my/widget/all" ] }
},
layerOptimize: "closure",
optimize: "closure",
cssOptimize: "comments",
mini: true,
stripConsole: "warn",
selectorEngine: "lite"
};
})();
据我所知,直接回答你的问题是否定的。您需要以某种方式列出您的依赖项。
但是您可以创建一个 all.js
文件,它基本上是一个模块,可以包含您的自定义小部件的所有依赖项。
这为您提供了将依赖项定义保持在 .profile.js
之外的优势。
使用示例可以使用自定义工具自动创建 all.js
,这样您在应用程序中创建模块时无需手动更新所有依赖项及其路径。
all.js
的示例(此文件可以手动或使用某些定制工具保持更新):
require([
'my/widget/AuthorWidget',
'my/widget/AuthorWidget2,
...
]);
在您的 profile.js
中仅包含 all.js
:
var profile = {
....
layers: {
"dojo/dojo": {
include: ["dojo/main" ],
customBase: true,
boot: true
}
, "my/widget": { include: [
"all"
]
}
},
....
}
我有一个这样定义的配置文件:
var profile = {
....
layers: {
"dojo/dojo": {
include: ["dojo/main" ],
customBase: true,
boot: true
}
, "my/widget": { include: [
"my/widget/AuthorWidget",
"my/widget/templates/AuthorWidget.html" ]
}
},
....
}
这就是我想要的。它创建文件 dojo.js 和 widget.js,其中包含我需要的所有内容。
有没有更好的方法来包含来自 my/widget 的所有文件而不将它们列在 include: 中? AuthorWidget.js 看起来像这样:
define([
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dojo/text!./templates/AuthorWidget.html",
"dojo/dom-style",
....
所以我希望包括来自 my/widget/templates/AuthorWidget.html 的每个相关小部件。不幸的是,我在 include: 数组中有这个文件,否则 dijig/form/Button 不会包含在结果中。 (我有 [button type="button" data-dojo-type="dijit/form/Button"]Click Me![/button] 在 AuthorWidget.html)
my.profile.js:
var profile = (function(){
return {
basePath: "./src",
releaseDir: "../release",
releaseName: "my",
action: "release",
defaultConfig: {
async: 1
},
packages:[{
name: "dojo",
location: "dojo"
},{
name: "dijit",
location: "dijit"
},{
name: "dojox",
location: "dojox"
},{
name: "my",
location: "../js/my",
destLocation: "myapp"
}],
layers: {
"dojo/dojo": {
include: ["dojo/main" ],
customBase: true,
boot: true
}
//this works
//, "my/widget": { include: [ "my/widget/AuthorWidget", "my/widget/templates/AuthorWidget.html" ] }
//this doesnt include Button widget required by AuthorWidget.html
, "my/widget": { include: [ "my/widget/all" ] }
},
layerOptimize: "closure",
optimize: "closure",
cssOptimize: "comments",
mini: true,
stripConsole: "warn",
selectorEngine: "lite"
};
})();
据我所知,直接回答你的问题是否定的。您需要以某种方式列出您的依赖项。
但是您可以创建一个 all.js
文件,它基本上是一个模块,可以包含您的自定义小部件的所有依赖项。
这为您提供了将依赖项定义保持在 .profile.js
之外的优势。
使用示例可以使用自定义工具自动创建 all.js
,这样您在应用程序中创建模块时无需手动更新所有依赖项及其路径。
all.js
的示例(此文件可以手动或使用某些定制工具保持更新):
require([
'my/widget/AuthorWidget',
'my/widget/AuthorWidget2,
...
]);
在您的 profile.js
中仅包含 all.js
:
var profile = {
....
layers: {
"dojo/dojo": {
include: ["dojo/main" ],
customBase: true,
boot: true
}
, "my/widget": { include: [
"all"
]
}
},
....
}