2

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.

Community
  • 1
  • 1
A. Duff
  • 4,097
  • 7
  • 38
  • 69
  • 2
    You've looked at the [sample r.js example build file](https://github.com/jrburke/r.js/blob/master/build/example.build.js)? – steveax Jan 31 '15 at 02:07
  • @steveax Thanks for pointing me to that. I still cannot get grunt-requirejs to build what I want, though. I'm trying to get it to take a directory of files and combine them into a minified, output file. I'm setting the `paths` property to load third-party libraries from a CDN, as well as other local modules. When I specify `appDir` I get an error that it's looking for a file like `undefinedcontrollers/foo-ctrl.js` If I set a baseUrl, it looks for everything included CDN-hosted libraries relative to that path (e.g. `/my/dir/http://some.cdn/angular` Do you know of any instructions on this? – A. Duff Feb 03 '15 at 19:06

0 Answers0