This commit is contained in:
Mondal 2025-10-03 01:13:45 +08:00 committed by GitHub
commit a15432a60b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 14 deletions

View File

@ -376,28 +376,40 @@ class LazyCompilationPlugin {
apply(compiler) {
/** @type {BackendApi} */
let backend;
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, (params, callback) => {
if (backend !== undefined) return callback();
const promise = this.backend(compiler, (err, result) => {
if (err) return callback(err);
backend = /** @type {BackendApi} */ (result);
callback();
});
if (promise && promise.then) {
promise.then((b) => {
backend = b;
compiler.hooks.beforeCompile.tapAsync(
PLUGIN_NAME,
(/** @type {any} */ params, /** @type {(err?: Error | null) => void} */ callback) => {
if (backend !== undefined) return callback();
const promise = this.backend(compiler, (err, result) => {
if (err) return callback(err);
backend = /** @type {BackendApi} */ (result);
callback();
}, callback);
});
if (promise && promise.then) {
promise.then((b) => {
backend = b;
callback();
}, callback);
}
}
});
);
compiler.hooks.thisCompilation.tap(
PLUGIN_NAME,
/**
* @param {import("../Compilation")} compilation
* @param {{ normalModuleFactory: import("../NormalModuleFactory") }} param1
*/
(compilation, { normalModuleFactory }) => {
normalModuleFactory.hooks.module.tap(
PLUGIN_NAME,
/**
* @param {Module} module
* @param {*} createData
* @param {*} resolveData
*/
(module, createData, resolveData) => {
if (
resolveData.dependencies.every((dep) =>
resolveData.dependencies.every((dep: any) =>
HMR_DEPENDENCY_TYPES.has(dep.type)
)
) {
@ -457,7 +469,7 @@ class LazyCompilationPlugin {
);
}
);
compiler.hooks.shutdown.tapAsync(PLUGIN_NAME, (callback) => {
compiler.hooks.shutdown.tapAsync(PLUGIN_NAME, (callback: (...args: any[]) => void) => {
backend.dispose(callback);
});
}