chore: switch to tar-fs for better stream support
This commit is contained in:
+20
-4
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user