@@ -75,6 +75,23 @@ function evalDependencyGraph({loaderContext, src, filename, publicPath = ""}) {
7575 }
7676 }
7777
78+ function extractQueryFromPath ( givenRelativePath ) {
79+ const indexOfLastExclMark = givenRelativePath . lastIndexOf ( "!" ) ;
80+ const indexOfQuery = givenRelativePath . lastIndexOf ( "?" ) ;
81+
82+ if ( indexOfQuery !== - 1 && indexOfQuery > indexOfLastExclMark ) {
83+ return {
84+ relativePathWithoutQuery : givenRelativePath . slice ( 0 , indexOfQuery ) ,
85+ query : givenRelativePath . slice ( indexOfQuery ) ,
86+ } ;
87+ }
88+
89+ return {
90+ relativePathWithoutQuery : givenRelativePath ,
91+ query : "" ,
92+ } ;
93+ }
94+
7895 async function evalModule ( src , filename ) {
7996 const rndPlaceholder = "__EXTRACT_LOADER_PLACEHOLDER__" + rndNumber ( ) + rndNumber ( ) ;
8097 const rndPlaceholderPattern = new RegExp ( rndPlaceholder , "g" ) ;
@@ -91,10 +108,8 @@ function evalDependencyGraph({loaderContext, src, filename, publicPath = ""}) {
91108 exports,
92109 __webpack_public_path__ : publicPath , // eslint-disable-line camelcase
93110 require : givenRelativePath => {
94- const indexOfQuery = Math . max ( givenRelativePath . indexOf ( "?" ) , givenRelativePath . length ) ;
95- const relativePathWithoutQuery = givenRelativePath . slice ( 0 , indexOfQuery ) ;
111+ const { relativePathWithoutQuery, query} = extractQueryFromPath ( givenRelativePath ) ;
96112 const indexOfLastExclMark = relativePathWithoutQuery . lastIndexOf ( "!" ) ;
97- const query = givenRelativePath . slice ( indexOfQuery ) ;
98113 const loaders = givenRelativePath . slice ( 0 , indexOfLastExclMark + 1 ) ;
99114 const relativePath = relativePathWithoutQuery . slice ( indexOfLastExclMark + 1 ) ;
100115 const absolutePath = resolve . sync ( relativePath , {
@@ -161,6 +176,9 @@ function rndNumber() {
161176 . slice ( 2 ) ;
162177}
163178
179+ // getPublicPath() encapsulates the complexity of reading the publicPath from the current
180+ // webpack config. Let's keep the complexity in this function.
181+ /* eslint-disable complexity */
164182/**
165183 * Retrieves the public path from the loader options, context.options (webpack <4) or context._compilation (webpack 4+).
166184 * context._compilation is likely to get removed in a future release, so this whole function should be removed then.
@@ -186,6 +204,7 @@ function getPublicPath(options, context) {
186204
187205 return "" ;
188206}
207+ /* eslint-enable complexity */
189208
190209// For CommonJS interoperability
191210module . exports = extractLoader ;
0 commit comments