2

I use r.js to cobble together all the js code in my SPA into 1 file. I use grunt's `grunt-contrib-requirejs' task for this, with the following:

requirejs: {
  compile: {
    options: {
      name: 'app',
      out: 'build/js/app.js',
      baseUrl: 'app',
      mainConfigFile: 'config/main.js',
      preserveLicenseComments: true,
      optimize: "none"
    }
  }
}

I also use a build task that zips the build folder into a zip file for me to send to our company's change management folks.

I would like to have two requirejs tasks - one that uglifies (for sending to CM) and one that doesn't (during development). Is this possible? I tried creating a new task with a different name and grunt yelled at me... should be simple. Is this possible? Are there any reasons not to do this?

Thanks in advance!

tengen
  • 2,125
  • 3
  • 31
  • 57

1 Answers1

7

Actually it is very simple:

requirejs: {
    compile: {
        options: {
            ...
            optimize: "none"
        }
    },
    compileForProduction: {
        options: {
            ...
            optimize: "uglify2"
        }
    }
}

(options are same as yours, with any diffs between the two that are required, e.g. optimize)

Run it with:

grunt requirejs:compileForProduction

or in Gruntfile.js:

grunt.registerTask("prod", ["requirejs:compileForProduction"]);

and:

grunt prod
Nikos Paraskevopoulos
  • 39,514
  • 12
  • 85
  • 90
  • This was so easy, thank you - exactly what I needed. Thanks again for taking the time to help me out! – tengen Nov 06 '13 at 14:51