javascriptrequirejsgruntjsgoogle-closure-compilergrunt-requirejs

How do I use Closure Compiler with grunt-requirejs?


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?


Solution

  • 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.