This branch is the esri-jsapi resource directory setup for creating single file dojo builds. It downloads dojo, the esri api, and CMV as bower resources and can be used to create high performance dojo builds using the dojo build system. The primary benefits are:
- Smaller downloads: only the modules used in an application are downloaded
- Quicker load times: HTML and Javascript files are concatenated and optimized into single files using the closure compiler. CSS are concatenated using xstyle
See the difference! Note: the load times shown below are not observed in a production environment, and should not be used for comparison.
Instead, Try The Demo for an realistic comparison.
Before:
After:
- node & npm
- bower
- grunt
- java 7 or greater - for Closure Compiler used during build
npm install -g bower
- installs bowernpm install -g grunt-cli
- installs global gruntnpm install
- installs required node and bower packagesnpm run clean
- removes built files fromdist
directorynpm run build-dev
- run the Dojo build on application but leave all files. Useful for debugging builds. This will result in a large folder size, although the browser shouldn't be requesting any extra files.npm run build
- run the Dojo build on application and run the cleanup tasks which remove all extra js and css files that aren't included in the build. If you add extra layers to the profile, theGruntfile.js
must be modified to account for this so these layers aren't removed!
- Use
build.profile.js
,viewer.js
, and other config files to add your layers. The current setup uses one large layer,dojo/dojo.js
. - Another option is to have one main layer
dojo/dojo.js
and several others like config files that are loaded on demand. - When adding layer files, both
build.profile.js
andGruntfile.js
clean task should be modified. Otherwise grunt will remove the file when it cleans up the build.
The dojo build system doesn't optimize packages between layers. Lets say you have 3 modules
- Module A
- Module B
- Module C
- Both A and B require C.
- We create 2 layer files A and B.
- Both layer files will have their own copy of C.
Maybe we should move away from dojo and use something like StealJS. What do you say, Esri?
##Troubleshooting
Instead of running grunt dojo-build
, instead try running build-viewer.sh
. This will give you a detailed error log in the dist directory called build-report.txt
. Errors begin with error(123) in the output. These errors will most likely be paths that do not resolve correctly.