Skip to content

Instantly share code, notes, and snippets.

@timmywil
Created February 7, 2013 15:20
Show Gist options
  • Save timmywil/4731580 to your computer and use it in GitHub Desktop.
Save timmywil/4731580 to your computer and use it in GitHub Desktop.
This is a shared module between server and client. It has one extra dependency in the browser because it should not be used on the server. This pattern was arrived at because it was the only one I found that worked after building with r.js. I'd like to suggest removing the entire if statement even if it has extra content such as defining empty m…
// For node
if (typeof define !== "function") {
var define = require("amdefine")( module );
// Define base64 as empty
define("libs/base64", function() {});
}
define([ "node-uuid", "libs/base64" ],
function( uuid, base64 ) {
function awesome() {
if ( typeof base64 === "function" ) {
// Use base64 module in browser
} else {
// Use .toString("base64") in Node
}
}
return awesome;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment