Created
March 21, 2014 11:17
-
-
Save nicolashery/9684078 to your computer and use it in GitHub Desktop.
Building UMD modules with dependencies with Browserify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var moment = require('moment'); | |
module.exports = { | |
now: function() { return moment().format(); }, | |
hello: function() { return 'Hello world'; } | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('lodash'); | |
var foo = require('./foo'); | |
module.exports = function () { | |
_.forEach(foo, function(fn, key) { | |
console.log(key, fn()); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dist: | |
browserify \ | |
--external lodash \ | |
--external moment \ | |
--require ./index.js:robot \ | |
> bundle.js | |
cat umd-head.js bundle.js umd-tail.js > robot.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(root, factory) { | |
if(typeof exports === 'object') { | |
module.exports = factory(require('lodash'), require('moment')); | |
} | |
else if(typeof define === 'function' && define.amd) { | |
define(['lodash', 'moment'], factory); | |
} | |
else { | |
root.robot = factory(root._, root.moment); | |
} | |
}(this, function(_, moment) { | |
var require = function(name) { | |
return {'G2vsx1': _, 'ZCrjYp': moment}[name]; | |
}; | |
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | |
var moment = require('moment'); | |
module.exports = { | |
now: function() { return moment().format(); }, | |
hello: function() { return 'Hello world'; } | |
}; | |
},{"moment":"ZCrjYp"}],"Focm2+":[function(require,module,exports){ | |
var _ = require('lodash'); | |
var foo = require('./foo'); | |
module.exports = function () { | |
_.forEach(foo, function(fn, key) { | |
console.log(key, fn()); | |
}); | |
}; | |
},{"./foo":1,"lodash":"G2vsx1"}],"robot":[function(require,module,exports){ | |
module.exports=require('Focm2+'); | |
},{}]},{},[]) | |
return require('robot'); | |
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(root, factory) { | |
if(typeof exports === 'object') { | |
module.exports = factory(require('lodash'), require('moment')); | |
} | |
else if(typeof define === 'function' && define.amd) { | |
define(['lodash', 'moment'], factory); | |
} | |
else { | |
root.robot = factory(root._, root.moment); | |
} | |
}(this, function(_, moment) { | |
var require = function(name) { | |
return {'G2vsx1': _, 'ZCrjYp': moment}[name]; | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return require('robot'); | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment