javascriptrequirejsgruntjsgrunt-contrib-requirejs

grunt requirejs 'define is undefined'


I'm trying to optimize RequireJS using GruntJS, using the grunt-contrib-requirejs plugin.

The problem is my code works fine before optimizing it, and then after optimizing it, on the console it says Uncaught ReferenceError: define is not defined.

Here's the Gruntfile.js

module.exports = function (grunt) {
  grunt.loadNpmTasks('grunt-contrib-requirejs');

  grunt.initConfig({
    requirejs: {
        compile : {
            options : {
              name  : 'main',
              baseUrl : ".",
              mainConfigFile : "./main.js",
              out : "./optimized.js",
              preserveLicenseComments: false
           }
        }
}
  })

  grunt.registerTask('default', 'requirejs');

}

Solution

  • As define is a requireJs function it seems you miss to load requireJs or any other AMD loader. If you dont need to load any other AMD module then your complied once, you can use a light weight loader shim like almond.