Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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');

}
like image 506
Otskimanot Sqilal Avatar asked Mar 06 '13 12:03

Otskimanot Sqilal


2 Answers

Adding the require.js file as an "include" option should work.

requirejs: {
    compile : {
        options : {
            name  : 'main',
            baseUrl : ".",
            mainConfigFile : "./main.js",
            out : "./optimized.js",
            preserveLicenseComments: false,
            include: ['path/to/require.js']
        }
    }
}
like image 142
Thomas Higginbotham Avatar answered Oct 18 '22 17:10

Thomas Higginbotham


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.

like image 26
Andreas Köberle Avatar answered Oct 18 '22 18:10

Andreas Köberle