Created
May 15, 2014 22:15
-
-
Save ifandelse/9c5964571cb684b96188 to your computer and use it in GitHub Desktop.
Using Lodash with Postal in place of underscore
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
// 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