如何在dojo构建层中包含所有文件?

时间:2016-06-01 17:06:29

标签: build dojo

我的个人资料定义如下:

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。

有没有更好的方法如何包含我的/ widget中的所有文件,而不在include中列出它们? AuthorWidget.js看起来像这样:

define([
    "dojo/_base/declare",
    "dijit/_WidgetBase",
    "dijit/_TemplatedMixin",
    "dojo/text!./templates/AuthorWidget.html",
    "dojo/dom-style",
....

所以我希望从我的/ widget / templates / AuthorWidget.html中包含每个依赖的小部件。不幸的是,我在include:数组中有这个文件,否则dijig / form / Button不包含在结果中。 (我有[按钮类型="按钮" data-dojo-type =" dijit / form / Button"]单击我![/ 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"
    };
})();

1 个答案:

答案 0 :(得分:1)

直接回答你的问题,据我所知是否定的。您需要以某种方式列出您的依赖项。

但是你可以创建一个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"
          ] 
       }
    },
....
}