RequireJS for single-file builds: revisited.
Someone recently started a github repo using RequireJS to build their ArcGIS JavaScript applications. This piqued my interest as it’s something I had done in the past, but at some point r.js or node didn’t work properly together anymore with my build file. Rather than fuss with it, I moved on to using Grunt to do my compile/minify/copy of files for production and testing.
So when I saw someone got r.js working with the ArcGIS JS API, I was drawn to it like a kid to an ice cream truck. The Dojo build tools have something against me, as every time I have tackled them, they just kick me in the nads and steal my lunch money. I really admire the AGRC guys for tackling Dojo build tools for the ArcGIS JS API, but it was just not my thing.
The base project so far does a real good job of showing how to build out minified files with just grunt-contrib-requirejs, but I wanted to actually get the mythical single file build working somehow. With some tweaking and some tears, I was able to wrangle the outputted single-file to work as expected. This of course, does not include the Esri/Dojo CDN bits, but it works and it even includes turning templates into their own modules to include them in the single file.
I like this. I like this a lot. I think I may try this on a couple of current projects to test it out. I might even include this trick in my ArcGIS Web Development book.
I’m not totally sold on a single file build as the Esri CDN is still making multiple calls to the server to download files as needed. So my single file build is a drop in the bucket of HTTP requests being made There will apparently be some news about custom builds coming out early next year, I’m guessing around Developer Summit time.
Still, this is pretty neat stuff, using RequireJS to optimize my Dojo code.