是否可以使用RequireJS加载自定义dojo构建?

时间:2015-09-21 17:55:52

标签: javascript optimization dojo requirejs dgrid

处理使用RequireJS的项目,并使用Require而不是Dojo加载器加载dojo / dijit / dojox / dgrid。

我正在尝试优化javascript以减少http调用,而RequireJS优化器似乎无法优化Dojo模块。

是否可以创建Dojo自定义构建然后使用RequireJS加载它?我已经尝试了一些构建,但还没有能够让它工作。我尝试过的最后一个Dojo构建配置(成功运行)是:

var profile = {
basePath: '../src/',
action: 'release',
cssOptimize: 'comments',
mini: true,
optimize: 'closure',
layerOptimize: 'closure',

packages: [
    'dgrid',
    'dijit',
    'dojo',
    'dojox',
    'put-selector',
    'xstyle'
],

stripConsole: 'all',
selectorEngine: 'lite',

layers: {
    'dojo/dojo': {
        boot: false,
        customBase: true,
        include: [
            'dojo/_base/array',
            'dojo/_base/declare',
            'dojo/_base/fx',
            'dojo/_base/lang',
            'dojo/_base/window',
            'dojo/_base/xhr',
            'dojo/aspect',
            'dojo/cache',
            'dojo/Deferred',
            //'dojo/dojo',
            'dojo/dom-class',
            'dojo/dom-construct',
            'dojo/dom-geometry',
            'dojo/dom-style',
            'dojo/dom',
            'dojo/fx',
            'dojo/has',
            'dojo/keys',
            'dojo/mouse',
            'dojo/on',
            'dojo/promise/all',
            'dojo/query',
            'dojo/request/registry',
            'dojo/request/util',
            'dojo/sniff',
            'dojo/string',
            'dojo/store/Cache',
            'dojo/store/JsonRest',
            'dojo/store/Memory',
            'dojo/store/Observable',
            'dojo/store/util/QueryResults',
            'dojo/topic',
            'dojo/when',
            'dojox/uuid/generateRandomUuid',
            'put-selector/put',
        ]
    },
    'dijit/dijit': {
        include: [
            'dijit/_TemplatedMixin',
            'dijit/_Widget',
            'dijit/dijit',
            'dijit/form/CheckBox',
            //'dijit/form/DateTextBox', // For some reason including this module causes the Dojo build to fail?
            //'dijit/form/FilteringSelect', // For some reason including this module causes the Dojo build to fail?
            //'dijit/form/MappedTextBox', // For some reason including this module causes the Dojo build to fail?
            'dijit/form/TextBox',
            'dijit/Menu',
            'dijit/MenuItem',
            'dijit/Tooltip',
        ]
    },
    'dgrid/dgrid': {
        include: [
            'dgrid/CellSelection', // Set the cell selection model
            'dgrid/ColumnSet', //Adds frozen column capabilities.
            'dgrid/Editor',
            //'dgrid/extensions/ColumnHider', // For some reason including this module causes the Dojo build to fail?
            'dgrid/extensions/ColumnReorder',
            'dgrid/extensions/ColumnResizer',
            'dgrid/extensions/CompoundColumns',
            'dgrid/Grid',
            'dgrid/Keyboard',
            'dgrid/OnDemandGrid',
            'dgrid/Tree',
            'dgrid/util/misc',
            'dgrid/util/touch',
        ]
    },

},

staticHasFeatures: {
    'config-deferredInstrumentation': 0,
    'config-dojo-loader-catches': 0,
    'config-tlmSiblingOfDojo': 0,
    'dojo-amd-factory-scan': 0,
    'dojo-combo-api': 0,
    'dojo-config-api': 1,
    'dojo-config-require': 0,
    'dojo-debug-messages': 0,
    'dojo-dom-ready-api': 1,
    'dojo-firebug': 0,
    'dojo-guarantee-console': 1,
    'dojo-has-api': 1,
    'dojo-inject-api': 1,
    'dojo-loader': 0,
    'dojo-log-api': 0,
    'dojo-modulePaths': 0,
    'dojo-moduleUrl': 0,
    'dojo-publish-privates': 0,
    'dojo-requirejs-api': 0,
    'dojo-sniff': 1,
    'dojo-sync-loader': 0,
    'dojo-test-sniff': 0,
    'dojo-timeout-api': 0,
    'dojo-trace-api': 0,
    'dojo-undef-api': 0,
    'dojo-v1x-i18n-Api': 1,
    'dom': 1,
    'host-browser': 1,
    'extend-dojo': 1
},

}

但是,当我尝试在require中加载优化的图层文件时,它会返回相当神秘的错误并且应用程序无法加载:

  

无法加载根模块。详细信息:has.add不是函数

此外,我在上面注释的一些模块会导致Dojo构建失败,如果我包含它们。那里有什么想法吗?

是否有可能使这项工作?目前我们与使用dgrid有关,所以如果这不起作用,唯一的选择就是剔除RequireJS。

提前致谢!

1 个答案:

答案 0 :(得分:0)

您需要使用Dojo Toolkit的source version。内置的AMD模块副本在加载器之间不兼容。