Skip to content

Instantly share code, notes, and snippets.

@brodock
Created February 8, 2017 19:42
Show Gist options
  • Save brodock/f8862a94e3494d2cc20689b4f8bd6dfa to your computer and use it in GitHub Desktop.
Save brodock/f8862a94e3494d2cc20689b4f8bd6dfa to your computer and use it in GitHub Desktop.
require 'therubyracer'
require 'commonjs'
webpack_path = `which webpack`.chomp
webpack_content = File.open(webpack_path).read.sub("#!/usr/bin/env node\n", '')
ctx = V8::Context.new
env = CommonJS::Environment.new(ctx, path: '/usr/local/lib/node_modules')
ctx['require'] = lambda { |this, module_id| env.require(module_id) }
# trying to get webpack "cli" to execute under therubyracer:
puts ctx.eval(webpack_content)
# the issue is that while I was able to inject require, it doesn find any npm module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment