2017-03-30 15:19:13 +08:00
|
|
|
import path from 'path'
|
|
|
|
|
import webpack from 'webpack'
|
2017-09-07 19:33:09 +08:00
|
|
|
import MemoryFS from 'memory-fs'
|
2017-03-30 15:19:13 +08:00
|
|
|
|
|
|
|
|
export function compileWithWebpack (file, extraConfig, cb) {
|
|
|
|
|
const config = Object.assign({
|
|
|
|
|
entry: path.resolve(__dirname, 'fixtures', file),
|
|
|
|
|
module: {
|
2017-03-30 21:34:39 +08:00
|
|
|
rules: [
|
|
|
|
|
{
|
|
|
|
|
test: /\.js$/,
|
|
|
|
|
loader: 'babel-loader'
|
|
|
|
|
},
|
2017-04-13 16:50:43 +08:00
|
|
|
{
|
|
|
|
|
test: /async-.*\.js$/,
|
|
|
|
|
loader: require.resolve('./async-loader')
|
|
|
|
|
},
|
2017-03-30 21:34:39 +08:00
|
|
|
{
|
2017-04-23 22:54:22 +08:00
|
|
|
test: /\.(png|woff2|css)$/,
|
2017-03-30 21:34:39 +08:00
|
|
|
loader: 'file-loader',
|
|
|
|
|
options: {
|
|
|
|
|
name: '[name].[ext]'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
2017-03-30 15:19:13 +08:00
|
|
|
}
|
|
|
|
|
}, extraConfig)
|
|
|
|
|
|
|
|
|
|
const compiler = webpack(config)
|
2017-09-07 19:33:09 +08:00
|
|
|
const fs = new MemoryFS()
|
2017-03-30 15:19:13 +08:00
|
|
|
compiler.outputFileSystem = fs
|
|
|
|
|
|
|
|
|
|
compiler.run((err, stats) => {
|
|
|
|
|
expect(err).toBeFalsy()
|
|
|
|
|
expect(stats.errors).toBeFalsy()
|
|
|
|
|
cb(fs)
|
|
|
|
|
})
|
|
|
|
|
}
|