1 | const webpack = require('webpack')
|
2 | const { print } = require('./stats')
|
3 |
|
4 | const cb = () => {}
|
5 |
|
6 | const compiler = (config, callback = cb) => {
|
7 | return new Promise((res, rej) => {
|
8 | const compiler = webpack(config)
|
9 | compiler.run((err, stats) => {
|
10 | if (err) {
|
11 | console.log('打包出错')
|
12 | console.log(err)
|
13 | rej(err)
|
14 | } else {
|
15 | print(stats)
|
16 | res()
|
17 | }
|
18 | })
|
19 | compiler.plugin('done', callback)
|
20 | })
|
21 | }
|
22 |
|
23 | module.exports = compiler
|