提交 c9669007 编写于 作者: J Jason Miller 提交者: Tim Neutkens

Bugfix/Performance: Start the modern child compiler earlier (#9257)

* Start the modern Child Compiler earlier during builds

* fix child compiler errors not bubbling
上级 c2a2417e
......@@ -254,24 +254,36 @@ export default class NextEsmPlugin implements Plugin {
}
}
compilation.hooks.additionalAssets.tapAsync(
PLUGIN_NAME,
childProcessDone => {
this.updateOptions(childCompiler)
childCompiler.runAsChild((err, entries, childCompilation) => {
if (err) {
return childProcessDone(err)
}
if (childCompilation.errors.length > 0) {
return childProcessDone(childCompilation.errors[0])
}
this.updateAssets(compilation, childCompilation)
childProcessDone()
})
}
)
// Hold back the main compilation until our Child Compiler has completed so its assets get optimized
const child = new Promise((resolve, reject) => {
// Defer the child compiler until known main thread "dead time" (while Terser is doing minification in the background)
let started = false
compilation.hooks.optimizeChunkAssets.intercept({
call: () => {
// only run the first time optimizeChunkAssets is called
if (started) return
started = true
// Delay the Child Compiler until optimizeChunkAssets has had time to send work to the Terser pool
setTimeout(() => {
this.updateOptions(childCompiler)
childCompiler.runAsChild((err, entries, childCompilation) => {
if (err) {
return reject(err)
}
if (childCompilation.errors.length > 0) {
return reject(childCompilation.errors[0])
}
this.updateAssets(compilation, childCompilation)
resolve()
})
}, 500)
},
})
})
compilation.hooks.optimizeAssets.tapPromise(PLUGIN_NAME, () => child)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册