I have a Javascript application spanning multiple files using RequireJS, which I want to concatenate into one for the production environment.
I've been looking at grunt-contrib-requirejs but the instructions for setting up the configuration in Gruntfile.js
assume that you already have the concatenated, production source. I'm aware that I could also use grunt-contrib-concat
for this, but I was wondering if there's a way to do it with the grunt-contrib-requirejs
module.
I've also tried using a wildcard selection for the name
field in the configuration, but although Grunt works fine with specifications like app/**/*.js
grunt-contrib-requirejs
doesn't concatenate them when I specify this.
I found this example on how to do this, but when I include multiple entries in the modules
array, running Grunt complains that certain files can't load their dependencies that are specified in the main file's require.config
.
For example, if this is main.js
:
require.config({
paths: {
'angular': 'http://some.cdn/angular.min'
},
shim: {
angular: {
exports: 'angular'
}
}
});
//Set up basic code
And this is controllers/ctrl.js
:
define(['angular'], function(angular) {
...
});
Then it's apparently not loading the configuration from main.js
and complains that there's no file /my/project/controllers/angular.js
I've also tried moving the configuration to a file specified with the mainConfigFile
option, but this option does not work and it seems that this option was meant to take the Grunt configuration and not the RequireJS configuration.