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)
this.updateOptions(childCompiler) let started = false
compilation.hooks.optimizeChunkAssets.intercept({
childCompiler.runAsChild((err, entries, childCompilation) => { call: () => {
if (err) { // only run the first time optimizeChunkAssets is called
return childProcessDone(err) if (started) return
} started = true
if (childCompilation.errors.length > 0) { // Delay the Child Compiler until optimizeChunkAssets has had time to send work to the Terser pool
return childProcessDone(childCompilation.errors[0]) setTimeout(() => {
} this.updateOptions(childCompiler)
this.updateAssets(compilation, childCompilation) childCompiler.runAsChild((err, entries, childCompilation) => {
childProcessDone() 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% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment