To use vanilla RequireJS to optimize your project, you’ll need to do two things:
- Create app.build.js - This file contains the configuration for how your want RequireJs react to your source code. Among other things, paths to source directories and output files are specified.
- Run the optimizer - via the command
node r.js -o app.build.js
Grunt has essentially the same steps, but they’re specified in the standard grunt config file and will integrate better with the rest of your build process steps that are in grunt.
Grunt RequireJs Configuration
An easy way to get Grunt to run your RequireJs build is to use the
Install the plugin:
npm install grunt-contrib-requirejs
Add the requirejs config to your grunt.js file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
And run the task:
You should get the regular RequireJs build output that you’re used to seeing, and you’ll be able to verify that it worked.