Last active
February 21, 2017 19:48
-
-
Save MadLittleMods/fd23fe19d287047ceb70f325f2fcd25a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const webpack = require('webpack'); | |
const MemoryFS = require('memory-fs'); | |
const memoryFs = new MemoryFS(); | |
memoryFs.writeFileSync('/entry1.js', `System.global = { foo: 'bar' };`, 'utf-8'); | |
const compiler = webpack({ | |
entry: '/entry1.js', | |
output: { | |
path: '/build/', | |
filename: 'main.js' | |
} | |
}); | |
compiler.inputFileSystem = memoryFs; | |
compiler.outputFileSystem = memoryFs; | |
compiler.resolvers.normal.fileSystem = compiler.inputFileSystem; | |
compiler.resolvers.context.fileSystem = compiler.inputFileSystem; | |
compiler.run((err, stats) => { | |
if(err) { | |
console.log(err); | |
} | |
const errors = stats.compilation.errors; | |
if (errors && errors.length > 0) { | |
console.log(errors); | |
throw errors[0]; | |
} | |
const content = memoryFs.readFileSync('/build/main.js', 'utf-8'); | |
//console.log(content); | |
eval(content); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment