Created
October 23, 2012 19:13
-
-
Save adorsk/3940948 to your computer and use it in GitHub Desktop.
trick for sharing same require_config w/ browser and node
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
fs = require('fs') | |
vm = require('vm') | |
requirejs = require('requirejs') | |
BASE_URL = __dirname + '/' | |
requireConfigPath = BASE_URL + 'js/require_config.js' | |
script = vm.createScript(fs.readFileSync(requireConfigPath)) | |
sandbox = { | |
require: requirejs, | |
BASE_URL: BASE_URL, | |
console: console | |
} | |
script.runInNewContext(sandbox) | |
requirejs.config({ | |
nodeRequire: require | |
}) | |
requirejs(['mod_a'], (modA) -> | |
console.log('here', modA) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment