Domanda

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!

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top