How do I use Closure Compiler with grunt-requirejs?

2.5k Views Asked by At

This is from my Gruntfile:

requirejs: {
  compile: {
    options: {
      almond: true,
      optimize: 'closure',
      baseUrl: '<%= cfg.src %>/scripts',
      mainConfigFile: '<%= cfg.src %>/scripts/config.js',
      out: '<%= cfg.staticDist %>/scripts/all.js',
      deps: ['app', 'config', 'bluebird', 'jquery']
    }
  }
},

When I set optimize to closure, grunt-requirejs writes this to console:

Running "requirejs:compile" (requirejs) task
>> Error: Error: optimizer with name of "closure" not found for this environment
>>     at Object.optimize.js (/Users/dan/Documents/Projects/test/node_modules/grunt-requirejs/node_modules/requirejs/bin/r.js:24632:27)

Does grunt-requirejs support optimising with Closure Compiler? Where do I need to put it?

2

There are 2 best solutions below

3
On BEST ANSWER

I think what you want to do here is that you want to use the more updated grunt-contrib-requirejs without optimization.

Then use a grunt task like grunt-closure-tools to optimize the combined files.

I found a user on GitHub that has success with this.

0
On

As Allan said and asciidisco confirmed:

We got rid of that. Caused too many troubles. Also, r.js only supports that (correct me if I´m wrong) if you´re in a rhino environment & because we are node only, we stick with uglify.

If you really wan't to use Closure Compiler, I recommend to run the task with no minification & apply a task such as grunt-closure-compiler to the optimised files later in your process.