AMD Module Format and Build Tools
Bryant Luk 270003TMDV Visits (2673)
The latest version of Dojo included in the Web 2.0 and Mobile Feature Pack for WebSphere includes many great enhancements that are laying the groundwork for future mobile and web development. There were many new things I learned while working on the feature pack. Two I wish to introduce are the new Asynchronous Module Definition (AMD) format and the build layers tooling. Developing your code into modules is a good practice, especially during development, as it helps with maintainability among other things. Once you are done with development though, you want to get the best loading performance possible, and the Dojo build layers tooling offers a way to minimize your code and package it into one file which reduces the overhead of multiple HTTP requests.
Asynchronous Module Definition (AMD)
Dojo has recently adopted the Asynchronous Module Definition (AMD) as the basis of its modularization going forward. While the Dojo community has always modularized their code, the AMD format brings new benefits. It helps define modules for asynchronous loading which helps with performance. Modules declared outside of Dojo can be more easily interoperable as more code is written in AMD format. Of course, you still get the benefits of only having to debug relatively small modules instead of huge code bases.
If you previously defined your own module, it should still work but you will not get the benefits of AMD. Looking at some of the new Dojo code, the first line in most files now is a AMD define() function call which replaces most of the dojo.require() calls.
An example of a module:
defiThe first optional argument is a module ID. The second optional argument is a list of modules required before this module should be loaded. The final argument is a function definition which defines your module.
AMD is a simple specification compared to many others I’ve read in the past. It defines a handful of functions and other conventions that you can follow while still providing all the benefits of modularized code. I encourage you to take a few minutes to read the AMD specification.
Build Layers Tooling
For official Dojo releases, you can check out the Dojo Web Builder which has a nice web interface for using the build tools.
You will need to use the command line tools directly for the new Dojo code written in the AMD format. The tools were re-written to understand the AMD format as well as with more options for better customization.
In a Dojo source distribution, the tools are included in the util/buildscripts directory. You may have to download additional tool prerequisites as detailed in the README files. The Dojo build tools take a profile configuration file which specifies what you want included in your layer. A few pre-defined profiles are included in the util
To do a standard build, you can change to the “util/buildscripts” directory and then run “build.bat profile=standard action=release version=1.7.0”. Replace “.bat” with “.sh” if you’re using a non-Windows operating system. This will produce a layer using the util/ buil
For more options in the build tool and to get more detailed help, you can check out the README in the util/buildscripts directory or you can run the “build.bat” or “build.sh” without any arguments.