mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
29c226771c
* Add AOT gzip content-encoding support. Currently we only do this for main.js and commons.js only. * Remove unwanted await. * Use Promise.all to gzip assets in parallel.
32 lines
707 B
JavaScript
32 lines
707 B
JavaScript
import webpack from './webpack'
|
|
import clean from './clean'
|
|
import gzipAssets from './gzip'
|
|
|
|
export default async function build (dir) {
|
|
const [compiler] = await Promise.all([
|
|
webpack(dir),
|
|
clean(dir)
|
|
])
|
|
|
|
await runCompiler(compiler)
|
|
await gzipAssets(dir)
|
|
}
|
|
|
|
function runCompiler (compiler) {
|
|
return new Promise((resolve, reject) => {
|
|
compiler.run((err, stats) => {
|
|
if (err) return reject(err)
|
|
|
|
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)
|
|
}
|
|
|
|
resolve()
|
|
})
|
|
})
|
|
}
|