« Back to Index

The power of r.js is incredible. insertRequire and onBuildRead are insanely useful in the right situation (not to mention other useful features such as fileExclusionRegExp, removeCombined and literally a ton more)…

View original Gist on GitHub

build.js

var config = {
    paths: { jquery: 'libs/jquery' },
    fileExclusionRegExp: /^\.|node_modules|Gruntfile|grunt-|libs|\.md|package.json/,
    baseUrl: './',
    modules: [
        { 
            name: 'bootstrap-about', 
            exclude: ['app'], 
            include: ['components/world/component'], 
            insertRequire: ['components/world/component'] 
        },
        { 
            name: 'bootstrap-index', 
            exclude: ['app'], 
            include: ['components/hello/component', 'components/world/component'], 
            insertRequire: ['components/hello/component', 'components/world/component'] 
        }
    ],
    dir: './release/',
    optimize: 'none',
    removeCombined: true,
    onBuildRead: function (moduleName, path, contents) {
        if (path.indexOf('bootstrap-') !== -1 || path.indexOf('/app.js') !== -1) {
            return '';
        } else {
            return contents;
        }
    }
};