Skip to content

Instantly share code, notes, and snippets.

@bumbu
Created May 17, 2014 20:18
Show Gist options
  • Save bumbu/2494a4441c280d484420 to your computer and use it in GitHub Desktop.
Save bumbu/2494a4441c280d484420 to your computer and use it in GitHub Desktop.
Conditional module loading in bower
module.exports = function(a){
console.log('child got '+a)
}
// Rename require so browserify will not be able to detect module requirement and will not bundle it
var loader = require
// On server side call parent file (as it supports require)
// On client side call built file (bundle)
if (typeof window === 'undefined') { // In node
var $$ = loader('./child')
} else {
var $$ = function(a) { // In browser
console.log('use local function, got: ' + a)
}
}
$$('from parent')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment