2016-10-17 01:54:36 +00:00
|
|
|
import webpack from './webpack'
|
2016-10-17 03:55:33 +00:00
|
|
|
import clean from './clean'
|
2016-12-29 22:38:19 +00:00
|
|
|
import gzipAssets from './gzip'
|
2016-10-06 11:05:52 +00:00
|
|
|
|
|
|
|
export default async function build (dir) {
|
2016-10-17 03:55:33 +00:00
|
|
|
const [compiler] = await Promise.all([
|
|
|
|
webpack(dir),
|
|
|
|
clean(dir)
|
|
|
|
])
|
2016-10-09 09:25:38 +00:00
|
|
|
|
2016-12-27 23:28:19 +00:00
|
|
|
await runCompiler(compiler)
|
2016-12-29 22:38:19 +00:00
|
|
|
await gzipAssets(dir)
|
2016-12-16 18:42:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function runCompiler (compiler) {
|
2016-10-17 01:54:36 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
compiler.run((err, stats) => {
|
|
|
|
if (err) return reject(err)
|
2016-10-06 11:05:52 +00:00
|
|
|
|
2016-10-17 01:54:36 +00:00
|
|
|
const jsonStats = stats.toJson()
|
|
|
|
if (jsonStats.errors.length > 0) {
|
|
|
|
const error = new Error(jsonStats.errors[0])
|
|
|
|
error.errors = jsonStats.errors
|
|
|
|
error.warnings = jsonStats.warnings
|
|
|
|
return reject(error)
|
|
|
|
}
|
2016-10-06 11:05:52 +00:00
|
|
|
|
2016-10-17 01:54:36 +00:00
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
})
|
2016-10-06 11:05:52 +00:00
|
|
|
}
|