Skip to content

Instantly share code, notes, and snippets.

@ifandelse
Created May 15, 2014 22:15
Show Gist options
  • Save ifandelse/9c5964571cb684b96188 to your computer and use it in GitHub Desktop.
Save ifandelse/9c5964571cb684b96188 to your computer and use it in GitHub Desktop.
Using Lodash with Postal in place of underscore
// Let's pretend we wanted to take the require js configuration from
// https://github.com/postaljs/postal.js/blob/master/example/amd/js/main.js
// and tell it to use lodash instead of underscore.
// Since postal 0.9.0 and earlier expect the module ID (in AMD
// environments) to be "underscore", all you have to do is define a path
// for "underscore" and point it to lodash:
require.config( {
paths : {
underscore : "../../../bower/lodash/lodash",
postal : "../../../lib/postal",
postaldiags : "../../../bower/postal.diagnostics/lib/postal.diagnostics",
jquery : "../../../bower/jquery/jquery.min"
}
} );
// IN a standard browser (no AMD or anything), lodash will be on the window as "_",
// and postal will use that.
// In a node setup, it's a little trickier (sorry).
// for pre 0.9.0 node you can use the factory function returned from postal:
var lodash = require('lodash');
var postal = require('postal')(lodash);
// in v0.9.0, the factory function was removed and the CommonJS module just exports
// postal itself. So - you unfortunately would need to edit the UMD wrapping postal:
// (this line: https://github.com/postaljs/postal.js/blob/master/lib/postal.js#L11)
module.exports = factory(require("lodash"), this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment