mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
798fd3c1e8
* compile _document using webpack * don't emit the bundle file of _document.js * exclude _document.js from minChunks of CommonsChunkPlugin * handle creation/removal of pages/_document.js * improve path handlings
30 lines
651 B
JavaScript
30 lines
651 B
JavaScript
import webpack from './webpack'
|
|
import clean from './clean'
|
|
|
|
export default async function build (dir) {
|
|
const [compiler] = await Promise.all([
|
|
webpack(dir),
|
|
clean(dir)
|
|
])
|
|
|
|
await runCompiler(compiler)
|
|
}
|
|
|
|
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()
|
|
})
|
|
})
|
|
}
|