Skip to content

Instantly share code, notes, and snippets.

@micmath
Created November 10, 2011 14:29
Show Gist options
  • Save micmath/1354964 to your computer and use it in GitHub Desktop.
Save micmath/1354964 to your computer and use it in GitHub Desktop.
pkgjs

http://mojo.codehaus.org/js-import-plugin/

modules.json

{
    "jquery": {
        "src": "file://Users/michael/scripts/vendor/jquery/1.7.0/jquery.js"
    },
    "underscore": {
        "src": "file://Users/michael/scripts/vendor/underscore/1.2.1/underscore.js",
        "build": "./lib/underscore.js"
    },
    "lib/mylib": {
        "src": "file://Users/michael/scripts/lib/mylib/0.1.1/main.js",
        "build": "./lib/mylib.js"
    }
}

myapp.js

/**
 * @import jquery as $
 * @import lib/mylib as mylib
 */

$(mylib.header).css({color: 'green'});

lib/mylib/0.1.1/main.js

/**
 * @module lib/mylib
 * @import underscore as _
 */

var mylib = {};
mylib.header = _.first(['header', 'article', 'footer']);

if (typeof exports !== 'undefined') exports.module = mylib;

console

$ pkgjs -m=../.pkgjs/modules.json -d=./dist myapp.js

./dist/myapp.js

require({
    paths: {
        'jquery': 'file://Users/michael/scripts/jquery/1.7.0/jquery',
        'underscore': 'lib/underscore',
        'mylib': 'lib/mylib'
    }
});

require(['jquery', 'mylib'], function($, mylib) {

$(mylib.header).css({color: 'green'});

});

./dist/lib/mylib.js

define('lib/mylib', ['undesrscore'], function(_) {

var mylib = {};
mylib.header = _.first(['header', 'article', 'footer']);

if (typeof exports !== 'undefined') exports.module = mylib;

});

./dist/lib/underscore.js

define('underscore', function() {
    // ...
    
    if (typeof exports !== 'undefined') exports.module = _;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment