Search code examples
javascriptrequirejsr.jsgrunt-contrib-requirejs

Using r.js to build entire project without needing overhead of require.js


I have a project with multiple javascript files, all formatted as AMD modules. I'm using r.js as part of my build process (using this grunt plugin to handle everything).

After I build my project, I end up with a concatenated, minified file that has jQuery, followed by all my modules ordered correctly. That said, these modules still make calls to require and define, so I need to include the entire require.js library when I send over my minified JS file to the client.

Is there any way I can build my JS such that I don't need to send require.js to the client? Like, when I build all my JS, can I just strip out the calls to define or require?

Any help would be greatly appreciated. This article from 2013 says there's no solution yet, but I'm hoping theres a fix now.

EDIT: One good suggestion I've heard is to use Almond.js, which I can do if that's the best solution to date. I was just hoping I didn't have to ship over any 3rd party library in the first place.


Solution

  • Use almond as a replacement for require.js in your built module. Have it loaded first to give you what you need.