How to use RequireJS with Dojo
As of Dojo 1.6, Dojo Core and Dijit have preliminary support for loading its modules with a loader like RequireJS that understands the AMD API proposal. Only a few of the Dojox modules have been converted to allow AMD loading.
AMD loading is still considered experimental in Dojo 1.6, and it only works by using a source distribution, not one of the built distributions.
Get the template § 1
Ben Hockey has set up a nice template project for getting started with Dojo+RequireJS. The directions are fairly straightforward. Some notes:
- The RequireJS i18n plugin does not support the equivalent of the djConfig.localeList. A future version of the RequireJS i18n plugin should support it.
- Dojox does not have it's own package config set up because not all of its modules have been converted to understand AMD syntax. Ben suggests one of two options if you want to use some modules in dojox (you need to inspect the modules yourself to see if they support AMD loading):
- Add a file similar to dijit/lib/main.js which returns the dojox object rather than the dijit object.
- Instead of using it like a package, just add a [baseUrl]/dojox.js with contents similar to dijit/lib/main.js