gruntjsgrunt-contrib-requirejsrequirejs-optimizer

Compiling with requirejs optimizer


I am trying to compile a project using requirejs optimizer and grunt (https://www.npmjs.org/package/grunt-contrib-requirejs). The output file of the compilation, is a single js file - but it still needs to be called from requirejs like so:

<script src="require.js" data-main="main.js"></script>

I need to compile the project using grunt in a way that I would not have to include requirejs into the script to execute the file; like so:

<script src="main.js"></script>

Here's my configuration for the requirejs grunt compiler:

requirejs:
      build:
        options:
          mainConfigFile : "client/main.js"
          baseUrl : "client"
          name: "main"
          out: "build/main.js"
          removeCombined: true
          findNestedDependencies: true

I would also expect to be able to get rid of require and define calls during this compilation.


Solution

  • This isn't exactly what you want, but I think you can replace requirejs with almondjs (optimized version of require js with less features)

    See Using almond with grunt-contrib-requirejs