【问题标题】:How to include all files in dojo build layer?如何在 dojo 构建层中包含所有文件?
【发布时间】:2016-06-01 17:06:29
【问题描述】:

我有一个这样定义的个人资料:

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。 (我在 AuthorWidget.html 中有 [button type="button" data-dojo-type="dijit/form/Button"]Click Me![/button])

我的.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"
    };
})();

【问题讨论】:

    标签: build dojo


    【解决方案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"
              ] 
           }
        },
    ....
    }
    

    【讨论】:

    • 您好,感谢您的回答。这适用于 AuthorWidget.js,但不适用于 my/widget/templates/AuthorWidget.html。在 authorWidget.html 中是具有 data-dojo-type="dijit/form/Button" 属性的按钮,结果中不包含 dijit/form/Button。如果我在 profile.js/include 数组中保留“my/widget/templates/AuthorWidget.html”,那么它可以工作。如果我将它移到 all.js,它不会...
    • @Petr 尝试在您的 .profile.js 上设置包属性,您需要在那里为 dijit 指定正确的路径。关于所有选项的更多信息可以在这里找到:dojotoolkit.org/documentation/tutorials/1.10/build如果你能修复它,请告诉我们:)
    • 我已阅读此内容,但我不知道会出现什么错误。正如我所说,将“my/widget/templates/AuthorWidget.html”放入 my.profile.js 可以正常工作(包括 dijit/form/Button 到结果 widget.js 中)。但是将它从 my.profile.js 移动到 all.js,它会停止包含 dijit/form/Button。它适用于 AuthorWidget 中的所有其他依赖项 - 它甚至在结果中包含 AuthorWidget.html 的内容。
    • @Petr 当构建解决您的模块时,这看起来像是一个问题。您能否发布您的完整版本的 .profile.js 和项目的文件夹结构?我可以试试看。
    • 我发现问题出在哪里。我的 AuthorWidget.js 文件中不需要 dijit/form/Button。需要要求模板中使用的所有小部件(而不是期望 parsr.parse() 下载它)
    猜你喜欢
    • 2013-07-06
    • 1970-01-01
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多