@@ -91,30 +91,31 @@ export function pitch(request) {
9191 childCompiler
9292 ) ;
9393 new LimitChunkCountPlugin ( { maxChunks : 1 } ) . apply ( childCompiler ) ;
94-
95- childCompiler . hooks . thisCompilation . tap (
96- `${ pluginName } loader` ,
97- ( compilation ) => {
98- compilation . hooks . normalModuleLoader . tap (
99- `${ pluginName } loader` ,
100- ( loaderContext , module ) => {
101- // eslint-disable-next-line no-param-reassign
102- loaderContext . emitFile = this . emitFile ;
103-
104- if ( module . request === request ) {
105- // eslint-disable-next-line no-param-reassign
106- module . loaders = loaders . map ( ( loader ) => {
107- return {
108- loader : loader . path ,
109- options : loader . options ,
110- ident : loader . ident ,
111- } ;
112- } ) ;
113- }
114- }
115- ) ;
94+ childCompiler . hooks . thisCompilation . tap ( `${ pluginName } loader` , ( compilation ) => {
95+ let { normalModuleLoader } = compilation . hooks ; // Webpack 4
96+ if ( ! normalModuleLoader ) {
97+ // Webpack 5+
98+ // eslint-disable-next-line global-require
99+ const NormalModule = require ( 'webpack/lib/NormalModule' ) ;
100+ normalModuleLoader = NormalModule . getCompilationHooks ( compilation ) . loader ;
116101 }
117- ) ;
102+
103+ normalModuleLoader . tap ( `${ pluginName } loader` , ( loaderContext , module ) => {
104+ // eslint-disable-next-line no-param-reassign
105+ loaderContext . emitFile = this . emitFile ;
106+
107+ if ( module . request === request ) {
108+ // eslint-disable-next-line no-param-reassign
109+ module . loaders = loaders . map ( ( loader ) => {
110+ return {
111+ loader : loader . path ,
112+ options : loader . options ,
113+ ident : loader . ident ,
114+ } ;
115+ } ) ;
116+ }
117+ } ) ;
118+ } ) ;
118119
119120 let source ;
120121
0 commit comments