我一直在阅读很多关于Dojo中的新功能(1.6之后)...是否可以构建一个.js文件,其中不仅包含dojo.js文件,还包含所有模块(及其页面所需的依赖项?
感谢。
答案 0 :(得分:6)
Dojo 1.x中的构建系统(AMD之前和之后)都支持构建层,这些构建层完全符合您的要求。您可以使用应用程序所需的顶级模块配置图层,然后构建过程将递归扫描依赖项,以在一个模块中包含应用程序模块所需的所有内容。
现代Dojo构建配置文件通常如下所示:
var profile = {
action: 'release',
basePath: 'src',
releaseDir: '../dist',
// Strip comments and newlines from CSS and flatten imports
cssOptimize: 'comments',
// Use the Closure compiler (which supports dead code removal)
// for layer optimization; uglify is also a choice
layerOptimize: 'closure',
// Specify the packages the build should scan
// (only include the ones you use; this follows the same format
// as the AMD packages option if you need to specify paths)
packages: [ 'dojo', 'dijit', 'dojox', 'app' ],
// Layers should always be defined over existing modules.
// You can define a layer over your own top-level application module,
// or you can redefine dojo/dojo so that all of your code is
// included as soon as you load dojo.js
layers: {
'dojo/dojo': {
// This layer includes the loader
boot: true,
// When building dojo/dojo, don't bundle all of dojo/_base
customBase: true,
include: [ 'app/main' ]
}
}
};
对于一个简单应用程序的理想构建配置文件,保证将所有内容构建到一个模块中,您最终只需要在生产中加载以下内容:
cssOptimize
)其他资源: