Skip to content

Additional requirejs configuration from package.json #112

Merged
merged 7 commits into from Dec 14, 2012

2 participants

@toddb
toddb commented Nov 30, 2012

Rebuild command has been extended to include from config section in the package.json. It is merged with jam packages and shims in require.config.js. The output from rebuild has been slightly changed to be compatible with r.js compilation.

Browser packages in package.json

You can also define your browser dependencies in a project-level package.json
file. If you use Node.js, this format will already familiar to you, and the
Jam dependencies can live alongside your NPM dependencies. It's also possible
to define custom install paths and baseUrls, as well as hand in any requirejs
configuration here:

{
    "name": "my-project",
    "version": "0.0.1",
    "description": "My example project",
    "jam": {
        "baseUrl": "public",
        "packageDir": "public/vendor",
        "dependencies": {
            "jquery": "1.7.x",
            "underscore": null
        },
        "config": {
          "paths": {
            "templates": "public/templates"
          }
        }
    }
}

Output: require.config.js

(fixed for r.js - it doesn't work with variable substitution)

var jam = {
    "packages": [
        {
            "name": "backbone",
            "location": "vendor/backbone",
            "main": "backbone.js"
        },
        {
            "name": "bootstrap",
            "location": "vendor/bootstrap"
        },
        {
            "name": "jquery",
            "location": "vendor/jquery",
            "main": "jquery.js"
        },
        {
            "name": "lodash",
            "location": "vendor/lodash",
            "main": "./lodash.js"
        },
        {
            "name": "text",
            "location": "vendor/text",
            "main": "text.js"
        },
        {
            "name": "underscore",
            "location": "vendor/underscore",
            "main": "underscore.js"
        },
        {
            "name": "underscore.string",
            "location": "vendor/underscore.string",
            "main": "./lib/underscore.string"
        }
    ],
    "version": "0.2.11",
    "shim": {
        "backbone": {
            "deps": [
                "jquery",
                "lodash"
            ],
            "exports": "Backbone"
        }
    }
};

if (typeof require !== "undefined" && require.config) {
    require.config({
    "paths": {
        "templates": "public/templates"
    },
    "packages": [
        {
            "name": "backbone",
            "location": "vendor/backbone",
            "main": "backbone.js"
        },
        {
            "name": "bootstrap",
            "location": "vendor/bootstrap"
        },
        {
            "name": "jquery",
            "location": "vendor/jquery",
            "main": "jquery.js"
        },
        {
            "name": "lodash",
            "location": "vendor/lodash",
            "main": "./lodash.js"
        },
        {
            "name": "text",
            "location": "vendor/text",
            "main": "text.js"
        },
        {
            "name": "underscore",
            "location": "vendor/underscore",
            "main": "underscore.js"
        },
        {
            "name": "underscore.string",
            "location": "vendor/underscore.string",
            "main": "./lib/underscore.string"
        }
    ],
    "shim": {
        "backbone": {
            "deps": [
                "jquery",
                "lodash"
            ],
            "exports": "Backbone"
        }
    }
});
}
else {
    var require = {
    "paths": {
        "templates": "public/templates"
    },
    "packages": [
        {
            "name": "backbone",
            "location": "vendor/backbone",
            "main": "backbone.js"
        },
        {
            "name": "bootstrap",
            "location": "vendor/bootstrap"
        },
        {
            "name": "jquery",
            "location": "vendor/jquery",
            "main": "jquery.js"
        },
        {
            "name": "lodash",
            "location": "vendor/lodash",
            "main": "./lodash.js"
        },
        {
            "name": "text",
            "location": "vendor/text",
            "main": "text.js"
        },
        {
            "name": "underscore",
            "location": "vendor/underscore",
            "main": "underscore.js"
        },
        {
            "name": "underscore.string",
            "location": "vendor/underscore.string",
            "main": "./lib/underscore.string"
        }
    ],
    "shim": {
        "backbone": {
            "deps": [
                "jquery",
                "lodash"
            ],
            "exports": "Backbone"
        }
    }
};
}

if (typeof exports !== "undefined" && typeof module !== "undefined") {
    module.exports = jam;
}
@caolan caolan merged commit d6058ed into caolan:master Dec 14, 2012
@caolan caolan added a commit that referenced this pull request Dec 14, 2012
@caolan make initial require config argument to updateRequireConfig optional,…
… fixes some issues with #112
be8df1e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.