Optimize require.js based projects
If you haven't used grunt before, be sure to check out the Getting Started guide.
From the same directory as your project's Gruntfile and package.json, install this plugin with the following command:
npm install grunt-requirejs
Once that's done, add this line to your project's Gruntfile:
grunt.loadNpmTasks('grunt-requirejs');
Inside your grunt.js
file add a section named requirejs
. This section specifies the options passed to RequireJS Optimizer.
This controls how this task (and its helpers) operate and should contain key:value pairs, see options below.
For a full list of possible options, see the r.js example build file.
Example require js optimizer config entry:
requirejs: {
compile: {
options: {
baseUrl: "path/to/base",
mainConfigFile: "path/to/config.js",
out: "path/to/optimized.js"
}
}
}
There is no difference between declaring your require config in your Gruntfile and using a separate requirejs config file.
grunt-requirejs is capable of replacing require.js with almond.js automatically
For more infos please take a look at the Almond Integration document
grunt-requirejs can generate custom jQuery, Lo-Dash & Backbone.js versions during the optimization
For more infos please take a look at the Using Custom Builds document
grunt-requirejs can minify your optimized output files using an hybrid strategy utilitizing uglifyjs & closure compiler
For more infos please take a look at the Using Hybrid Builds document
grunt-requirejs lets you specify a custom r.js for your build
For more infos please take a look at the Using Custom r.js versions document
grunt-requirejs can generate sourcemaps when using the r.js v2.1.2 or higher
For more infos please take a look at the Using Source Maps document
There are some project & configuration examples to get you startet:
Check the Changleog for more information
If you like to file an issue or submit a pull request, please check the contributing guidelines
Check the AUTHORS File for more information
- grunt
- Getting Started
- requirejs
- almond
- grunt-lodashbuilder
- grunt-jquerybuilder
- grunt-backbonebuilder
Copyright (c) 2012 Sebastian Golasch Licensed under the MIT license.