Commit c9669007 authored by Jason Miller's avatar Jason Miller Committed by 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
parent c2a2417e
...@@ -254,24 +254,36 @@ export default class NextEsmPlugin implements Plugin { ...@@ -254,24 +254,36 @@ export default class NextEsmPlugin implements Plugin {
} }
} }
compilation.hooks.additionalAssets.tapAsync( // Hold back the main compilation until our Child Compiler has completed so its assets get optimized
PLUGIN_NAME, const child = new Promise((resolve, reject) => {
childProcessDone => { // 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) this.updateOptions(childCompiler)
childCompiler.runAsChild((err, entries, childCompilation) => { childCompiler.runAsChild((err, entries, childCompilation) => {
if (err) { if (err) {
return childProcessDone(err) return reject(err)
} }
if (childCompilation.errors.length > 0) { if (childCompilation.errors.length > 0) {
return childProcessDone(childCompilation.errors[0]) return reject(childCompilation.errors[0])
} }
this.updateAssets(compilation, childCompilation) this.updateAssets(compilation, childCompilation)
childProcessDone() resolve()
}) })
} }, 500)
) },
})
})
compilation.hooks.optimizeAssets.tapPromise(PLUGIN_NAME, () => child)
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment