Skip to content

Commit f543839

Browse files
author
sunft1996
committed
feat: replace incompatible normal-module-loader hook
1 parent d282c1f commit f543839

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

__tests__/setups/v5-mini-css-extract-plugin/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ const options = {
5050
},
5151
};
5252

53-
module.exports = smp.wrap(options);
53+
module.exports = options;

index.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,26 @@ module.exports = class SpeedMeasurePlugin {
253253
});
254254

255255
tap(compiler, "compilation", (compilation) => {
256-
tap(compilation, "normal-module-loader", (loaderContext) => {
257-
loaderContext[NS] = this.provideLoaderTiming;
258-
});
256+
const { webpack } = compiler;
257+
258+
// normal-module-loader has been abandoned in webpack5
259+
if (
260+
webpack &&
261+
typeof webpack.version === "string" &&
262+
webpack.version.split(".")[0] >= 5
263+
) {
264+
const { NormalModule } = webpack;
265+
NormalModule.getCompilationHooks(compilation).loader.tap(
266+
"SpeedMeasureWebpackPlugin",
267+
(loaderContext) => {
268+
loaderContext[NS] = this.provideLoaderTiming;
269+
}
270+
);
271+
} else {
272+
tap(compilation, "normal-module-loader", (loaderContext) => {
273+
loaderContext[NS] = this.provideLoaderTiming;
274+
});
275+
}
259276

260277
tap(compilation, "build-module", (module) => {
261278
const name = getModuleName(module);

0 commit comments

Comments
 (0)