title: Require.js build not concatenation scripts loaded with Jam
body: <p>Following one of the chapters of "<em>Developing Backbone.js Apllication</em>" by Addy Osmani (O'Reilly) about <a href="https://github.com/backbone-boilerplate/grunt-bbb" rel="nofollow">Grunt-BBB (Backbone Boilerplate Buddy)</a>, I just couldn't manage to create a build profile.</p>
  
  <p>Here is the filesystem tree used for this :</p>
  
  <pre><code>/builds
      /closure
      /rhino
      /config
          /build.js
      build.sh
  /development
      /* Grunt-BBB files after init */
      /app
          /styles
              index.css
          app.js
          config.js
          main.js
          router.js
      /test
          /* Not important files used for testing */
      /vendor
          /h5bp
              /css
                  main.css
                  normalize.css
          /jam
              /backbone
                  backbone.js
                  package.json
              /bakbone.layoutmanager
                  bakbone.layoutmanager.js
                  package.json
              /jquery
                  jquery.js
                  package.json
              /lodash
                  lodash.js
                  lodash.min.js
                  lodash.underscore.min.js
                  package.json
              require.config.js
              require.js
          /js
              /libs
                  almond.js
                  require.js
  /distribution
      /* Empty dist directory where the optimized / minified / concatenated files should go */
  </code></pre>
  
  <p>Here are the steps I followed in the <code>/development</code> directory :</p>
  
  <p>1) Install Grunt-BBB (<code>npm install -g bbb</code>)</p>
  
  <p>2) Download r.js, a part of the Require.js project (<code>git clone https://github.com/backbone-boilerplate/grunt-bbb</code>)</p>
  
  <p>3) Initialize the files of the boilerplate (<code>bbb init</code>)</p>
  
  <p>Here is the build.js file I used to configure the r.js AMD loader for the Google Closure compiler :</p>
  
  <pre><code>({
      appDir: '../../development',
      baseUrl: 'app',
      dir: '../../distribution',
      optimize: 'closure', // 'uglify2'
      paths: {
          backbone: '../vendor/jam/backbone/backbone',
          'backbone.layoutmanager': '../vendor/jam/backbone.layoutmanager/backbone.layoutmanager',
          jquery: '../vendor/jam/jquery/jquery',
          lodash: '../vendor/jam/lodash/backbone.min'
      },
      modules: [
          {
              name: 'main'
          }
      ],
      onBuildRead: function(moduleNames, path, contents) {
          return contents;
          //return contents.replace(/console\.log\(([^\)]+)\);/g, '')
          //              .replace(/debugger;/, '');
      }
  })
  </code></pre>
  
  <p>and this is the build.sh file I use :</p>
  
  <pre><code>#!/usr/bin/env bash
  
  # r.js directory
  RJSDIR="r.js"
  RJS="$RJSDIR/dist/r.js"
  
  # Rhino directory
  RHINODIR="rhino"
  RHINO="$RHINODIR/js.jar"
  
  # Google Closure Compiler directory
  CLOSUREDIR="closure"
  CLOSURE="$CLOSUREDIR/compiler.jar"
  
  # Build config directory
  CONFIGDIR="config"
  CONFIG="$CONFIGDIR/build.js"
  
  # Launch compillation
  java -Xms256m -Xmx256m -classpath "$RHINO":"$CLOSURE" org.mozilla.javascript.tools.shell.Main "$RJS" -o "$CONFIG" $@
  </code></pre>
  
  <p>My goal is to optimize, minify, concatenate all the JavaScrit file including the libraries and templates (which I don't have yet, I am only using the boilerplate files) but also CSS files.</p>
  
  <p>The result I get by running <code>./build.sh</code> is that every files are correctly minimised (besides CSS rule inlining, but that is besides the point) and concatenated but resources that are loaded and managed by the Jam (package manager that combines NPM and Require.js) aren't concatenated.</p>
  
  <p>The reason for that since they are already loaded / managed by Jam, they are not redeclared in the JavaScript files AMD style.</p>
  
  <p>In conclusion, my questions are the following :</p>
  
  <ul>
  <li><p>How can I rewrite my <code>build.js</code> configuration file so that resources that are loaded by Jam also get included and concatenated in the release / dist file ?</p></li>
  <li><p>How can I make it so that the concatenated resources aren't copied in the realse / dist directory ? Is it possible to configure this in the <code>build.js</code> file or should this go in my <code>build.sh</code> file ?</p></li>
  </ul>
  
  <p><strong>Edit</strong> : New build.js file :</p>
  
  <pre><code>({
      appDir: '../../development',
      baseUrl: 'app',
      dir: '../../distribution',
      optimize: 'closure', // 'uglify2'
      paths: {
          requirejs : '../vendor/jam/require',
          backbone: '../vendor/jam/backbone/backbone',
          'backbone.layoutmanager': '../vendor/jam/backbone.layoutmanager/backbone.layoutmanager',
          jquery: '../vendor/jam/jquery/jquery',
          lodash: '../vendor/jam/lodash/backbone.min'
      },
      name: 'main',
      include: ['requirejs'],
      onBuildRead: function(moduleNames, path, contents) {
          return contents;
          //return contents.replace(/console\.log\(([^\)]+)\);/g, '')
          //              .replace(/debugger;/, '');
      }
  })
  </code></pre>
  
  <p>And here is the error :</p>
  
  <pre><code>file:///vendor/js/libs/require.jsFailed to load resource: The requested URL was not found on this server.
  file:///app/styles/index.cssFailed to load resource: The requested URL was not found on this server.
  </code></pre>