3

我一直在努力学习基于 AMD 的 Dojo 构建系统。到目前为止,我还无法获得一个可用的构建,而不会在浏览器 (FF) 中出现加载错误。

我对如何管理构建有疑问。

我的构建配置文件有一个包部分。我在那里指定的内容似乎与写入目标目录的相同包目录直接相关。这似乎很合适。但是,我还有一个图层部分,它试图仅合并来自 dojo、dijit、dojox 等的“引用”模块。当它们合并到一个 dojo.js 文件中时,我的目标目录中仍然有所有这些库目录. 您是否理解您只是手动进入并删除它们,或者是否有一种自动方法可以在构建过程中将它们删除?

在我的第一层中,我尝试为 dojo、dijit 和 dojox/app/main 构建它。这不会拉取任何资源,例如 dojo/resources/blank.gif 或同一目录中的任何 .css 文件。如何将这些资源文件复制到目的地?我相信 dojo.profile.js (确实表明要复制这些资源)只会影响 dojo 目录。但是由于我正在创建一个结合了 js 模块的自定义 dojo/dijit/dojox 文件,所以没有资源目录。在自定义构建之后,我是否应该手动进入 dojo 目录并将 dojo/resources 目录移出但扔掉 dojo 目录的其余部分?只是不确定如何在构建 dojo/dijit 层时获取 dojo 目录中可访问的依赖 img 和 css 文件,以便与自定义 dojo.js 层文件一起使用。

这是我的构建配置文件:

var profile = {
    basePath: "./",
    //releaseDir: "irb-release",
    action: "release",
    cssOptimize: "comments",
    stripConsole: 'all',
    selectorEngine: 'acme',
    layerOptimize: 'closure',
    optimize: 'closure',
    mini: true,
    packages:[
            { name: "dojo",         location: "../libs/dojo" },
            { name: "dijit",        location: "../libs/dijit" },
            { name: "dojox",        location: "../libs/dojox" },
            { name: "dgrid",        location: "../libs/dgrid" },
            { name: "put-selector", location: "../libs/put-selector" },
            { name: "xstyle",       location: "../libs/xstyle" },
            { name: "myPkg",     location: "../libs/myPkg" },
            { name: "irb",          location: "../irb" }
    ],
    layers: {
            "release/irb/libs/dojo": {
                    include: ["dojo/dojo", "dijit/dijit", "dojox/app/main"],
                    boot: true,
                    customBase: true
            },
            "release/irb/libs/myPkg": {
                    include: [
                            "myPkg/dialog/MessageBox",
                            "myPkg/grids/FilterGrid",
                            "myPkg/util/WidgetMonitor",
                            "myPkg/controllers/BorderLayout",
                            "myPkg/controllers/UnloadViewController"
                     ],
                    includeLocales: [ 'en-us' ]
            },
            "release/irb/libs/store/Memory": {
                    include: [ "dojo/store/Memory" ]
            },
            "release/irb/libs/store/Observable": {
                    include: [ "dojo/store/Observable" ]
            },
            "irb/irb": {
                    include: [
                            "irb/irb",
                            "dojox/app/View",
                            "dojox/css3/transit",
                            "dojox/app/controllers/Load",
                            "dojox/app/controllers/Transition",
                            "dojox/app/controllers/History"
                    ]
            }
    },

    staticHasFeatures: {
            // The trace & log APIs are used for debugging the loader, so we do not need them in the build.
            'dojo-trace-api': 0,
            'dojo-log-api': 0,

            // This causes normally private loader data to be exposed for debugging. In a release build, we do not need
            // that either.
            'dojo-publish-privates': 0,

            // This application is pure AMD, so get rid of the legacy loader.
            'dojo-sync-loader': 0,

            // `dojo-xhr-factory` relies on `dojo-sync-loader`, which we have removed.
            'dojo-xhr-factory': 0,

            // We are not loading tests in production, so we can get rid of some test sniffing code.
            'dojo-test-sniff': 0
    }
}; 

更新:这是我的目录结构,大约是。基于 dojox/app 结构:

/(webroot)
    /irb
        /controllers
        /res
            /css
            /img
        /views
        build.sh
        config.json
        index.html
        irb.js
        package.js
        package.json
        release.profile.js
    /libs
        /dgrid
        /dijit
        /dojo
        /dojox
        /myPkg
        /put-selector
        /util
        /xstyle

对于构建,我使用基于 dojox/app 示例的 build.sh 文件,但它调用的内部命令行是:

node "/home/(user)/(project ... path)/(webroot)/libs/dojo/dojo.sh" 
  load=build 
  --require "/home/(user)/(project ... path)/(webroot)/irb/irb.js" 
  --profile "/home/(user)/(project ... path)/(webroot)/irb/release.profile.js"
  --appConfigFile "/home/(user)/(project ... path)/(webroot)/irb/config.json"
  --releaseDir "/home/(user)/(project ... path)/(webroot)/build" 
4

1 回答 1

2

额外的文件和目录

我认为不删除它们是一个好习惯。执行构建的原因是通过将使用的所有内容组合到几个(最好是一个)javascript 文件中来提高 Web 浏览器的性能。

但是如果使用的文件(模块)不包含在层中会发生什么。如果您在构建目录中有其他文件,应用程序仍然可以工作,您只需额外调用服务器来获取该文件。如果您删除了这些目录和文件,您的应用程序将中断。


拉取资源

在进行自定义构建后,我有一个

release/RELEASE_NAME/dojo/resources 

目录,其中包含您提到的所有资源。


编辑:添加示例...

例子

命令

node path/to/dojo/dojo.js 
    load=build --profile path/to/build.profile.js --release --version=1.9.0

build.profile.js

var profile = (function(){
    return {
        // Assuming that the node command is being run in 
        // the webroot directory.  If not, update the basePath
        // to the libs directory using the current directory as
        // the starting point.
        basePath:        "./libs",

        releaseDir:      "/path/to/release/dir",
        action:          "release",
        releaseName:     "release",
        layerOptimize:   "shrinksafe",
        optimize:        false,
        cssOptimize:     "comments",
        mini:            false,
        stripConsole:    "normal",
        selectorEngine:  "acme",

        packages:[
            {name: 'dojo', location: 'dojo'},
            {name: 'dijit', location: 'dijit'},
            {name: 'dojox', location: 'dojox'},
            {name: 'dgrid', location: 'dgrid'},
            {name: 'put-selector', location: 'put-selector'},
            {name: 'xstyle', location: 'xstyle'}
            {name: 'irb', location: '../irb'},
        ],
        layers: {
            'irb/dojo": {
                include: ["dojo/dojo", "dijit/dijit", "dojox/app/main"],
                boot: true,
                customBase: true
            },
            ...
        }
    };
})();
于 2013-07-19T12:43:24.480 回答