问题
I've been struggling with learning the AMD based Dojo build system. So far I haven't been able to get a build that is usable without getting load errors in the browser (FF).
I have questions about how to manage the build.
My build profile file has a packages section. What I specify there seems to directly correlate to those same package directories being written into the destination directory. This seems appropriate. However, I also have a layers section that is trying to merge just the "referenced" modules from dojo, dijit, dojox, etc. When they get combined into one dojo.js file, I still have all those library directories in my destination dir. Is it understood that you just manually go in and remove them or is there an automatic way to get them removed during the build?
In my first layer I try to build it for dojo, dijit and dojox/app/main. This is not pulling over any resources, such as dojo/resources/blank.gif or any .css files in that same directory. How does one get those resource files to copy over to the destination? I believe dojo.profile.js (which does indicate to copy those resources) only impacts the dojo directory. But since I am creating a custom dojo/dijit/dojox file that combines js modules, there is no resources directory. After the custom build, am I supposed to manually go into the dojo directory and move the dojo/resources dir out but toss the rest of the dojo dir? Just not sure how to get the dependent img and css files accessible in the dojo dir for use with the custom dojo.js layer file when a dojo/dijit layer is built.
Here's my build profile:
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
}
};
UPDATE: Here is my directory structure which is approx. based on the dojox/app structure:
/(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
For the build i use the build.sh file based on dojox/app example but the internal command line it calls is:
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"
回答1:
Extra files and directories
I think it is a good practice to not remove them. The reason for performing a build is to improve web browser performance by combining everything that is used into a few (preferably one) javascript file.
But what happens if a file(module) that is used is not included in a layer. If you have the other files in the build directory, the application will still work, you will just have an additional call to the server to get that file. If you have removed these directories and files, your application will break.
Pulling over resources
After doing a custom build, I have a
release/RELEASE_NAME/dojo/resources
directory, which contains all the resources you mentioned.
EDIT: Adding example...
Example
Command
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
},
...
}
};
})();
来源:https://stackoverflow.com/questions/17736686/dojo-custom-build-getting-browser-errors-due-to-missing-resources