javascriptrequirejsgruntjsalmond

Using almond with grunt-contrib-requirejs


I'm trying to set up a gruntfile that utilizes requirejs and almond. The docs suggest it should be really easy, and following their lead, I tried:

requirejs: {
  compile: {
    options: {
      baseUrl: "tmp",
      mainConfigFile: "tmp/main.js",
      name: "../bower_components/almond/almond",
      out: "tmp/<%= pkg.name %>.js"
    }
  }
}

Unfortunately, this approach compiles almond.js rather than my actual source. Am I getting something wrong? How do I automate almond along with requirejs?


Solution

  • The trick is to use include:

    requirejs: {
      compile: {
        options: {
          baseUrl: "tmp",
          mainConfigFile: "tmp/main.js",
          include: "main",
          name: "../bower_components/almond/almond",
          out: "tmp/<%= pkg.name %>.js"
        }
      }
    }
    

    Where main is the require.js file you would typically call like so:

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