Created
May 17, 2014 20:18
-
-
Save bumbu/2494a4441c280d484420 to your computer and use it in GitHub Desktop.
Conditional module loading in bower
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
module.exports = function(a){ | |
console.log('child got '+a) | |
} |
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
// 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