chore: switch to tar-fs for better stream support

This commit is contained in:
calebboyd
2017-04-30 00:48:54 -05:00
parent ca7874c854
commit 1f35fe498e
10 changed files with 89 additions and 53 deletions
+20 -4
View File
@@ -1,32 +1,48 @@
import Mfs from 'memory-fs'
import webpack from 'webpack'
import { fromCallback } from 'bluebird'
import { resolve, join, relative } from 'path'
import { resolveModule } from './util'
import { resolve, join } from 'path'
import module from 'module'
import 'json-loader'
import 'html-loader'
const isObject = (x) => typeof x === 'object'
const isString = (x) => typeof x === 'string'
function loadModule (path) {
console.log('loading module!!!!', path)
return module._load(path, module, false)
}
export default async function bundle (compiler, next) {
let bundleConfig = compiler.options.bundle
if (!bundleConfig) {
return next()
}
const input = compiler.options.input || require.resolve(process.cwd())
const input = compiler.options.input || resolveModule(process.cwd())
const mfs = new Mfs()
const path = resolve('nexe')
const filename = 'virtual-bundle.js'
if (isString(bundleConfig)) {
bundleConfig === require(relative(process.cwd(), bundleConfig))
bundleConfig = loadModule(relative(process.cwd(), bundleConfig))
} else if (!isObject(bundleConfig)) {
bundleConfig = {
entry: resolve(input),
target: 'node',
output: { path, filename }
module: {
rules: [
{ test: /\.html$/, use: 'html-loader' },
{ test: /\.json$/, use: 'json-loader' }
]
}
}
}
bundleConfig.output = { path, filename }
const bundler = webpack(bundleConfig)
bundler.outputFileSystem = mfs
const stats = await fromCallback(cb => bundler.run(cb))