-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.js
37 lines (32 loc) · 967 Bytes
/
compile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const Debug = require('debug')
const webpack = require('webpack')
const webpackConfig = require('./webpack.config')
const prettyBytes = require('pretty-bytes')
const debug = Debug('webpack')
const compilerStats = {
chunks: true,
chunkModules: false,
colors: true,
errorDetails: true
}
module.exports = function (outDir, cb) {
debug('Create webpack compiler.')
const compiler = webpack(webpackConfig(outDir))
compiler.run(function (err, stats) {
const jsonStats = stats.toJson()
debug('Webpack compile completed.')
if (err) {
debug('Webpack compiler encountered a fatal error.', err)
cb(err)
} else if (jsonStats.errors.length > 0) {
debug('Webpack compiler encountered errors.')
cb(jsonStats.errors)
} else if (jsonStats.warnings.length > 0) {
debug('Webpack compiler encountered warnings.')
cb(null)
} else {
debug('No errors or warnings encountered.')
cb(null)
}
})
}