Skip to content

Instantly share code, notes, and snippets.

@adorsk
Created October 23, 2012 19:13
Show Gist options
  • Save adorsk/3940948 to your computer and use it in GitHub Desktop.
Save adorsk/3940948 to your computer and use it in GitHub Desktop.
trick for sharing same require_config w/ browser and node
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