feat: next

This commit is contained in:
calebboyd
2017-04-09 14:26:29 -05:00
parent 72afbe68a4
commit 7668d7b471
50 changed files with 1932 additions and 1563 deletions
+46
View File
@@ -0,0 +1,46 @@
const Mfs = require('memory-fs'),
webpack = require('webpack'),
{ fromCallback } = require('bluebird'),
{ resolve, join, relative } = require('path'),
isObject = (x) => typeof x === 'object',
isString = (x) => typeof x === 'string'
function* bundle (compiler, next) {
let bundleConfig = compiler.options.bundle
if (!bundleConfig) {
return next()
}
const
input = compiler.options.input || require.resolve(process.cwd()),
fs = new Mfs(),
path = resolve('nexe'),
filename = 'virtual-bundle.js'
if (isString(bundleConfig)) {
bundleConfig === require(relative(process.cwd(), bundleConfig))
} else if (!isObject(bundleConfig)) {
bundleConfig = {
entry: resolve(input),
target: 'node',
output: { path, filename }
}
}
const bundler = webpack(bundleConfig)
bundler.outputFileSystem = fs
const stats = yield fromCallback(cb => bundler.run(cb))
if (stats.hasErrors()) {
compiler.log.error(stats.toString())
return null
}
//eslint-disable-next-line no-sync
compiler.input = fs.readFileSync(
join(bundleConfig.output.path, bundleConfig.output.filename)
)
return next()
}
module.exports.bundle = bundle