This commit is contained in:
dgaponov 2025-12-20 08:30:55 +01:00 committed by GitHub
commit bc718ba8dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,11 +13,17 @@ function getCompilerHook(
{ id, entry, filename, chunkFilename, plugins }: IAddWorkerEntryPointPluginOptions { id, entry, filename, chunkFilename, plugins }: IAddWorkerEntryPointPluginOptions
) { ) {
const webpack = compiler.webpack ?? require('webpack'); const webpack = compiler.webpack ?? require('webpack');
let alreadyCompiled = false;
return function ( return function (
compilation: webpack.Compilation, compilation: webpack.Compilation,
callback: (error?: Error | null | false) => void callback: (error?: Error | null | false) => void
) { ) {
if (alreadyCompiled) {
callback();
return;
}
const outputOptions = { const outputOptions = {
filename, filename,
chunkFilename, chunkFilename,
@ -33,7 +39,14 @@ function getCompilerHook(
new SingleEntryPlugin(compiler.context, entry, 'main').apply(childCompiler); new SingleEntryPlugin(compiler.context, entry, 'main').apply(childCompiler);
plugins.forEach((plugin) => plugin.apply(childCompiler)); plugins.forEach((plugin) => plugin.apply(childCompiler));
childCompiler.runAsChild((err?: Error | null) => callback(err)); childCompiler.runAsChild((err?: Error | null) => {
if (err) {
callback(err);
} else {
alreadyCompiled = true;
callback();
}
});
}; };
} }