@@ -17,13 +17,26 @@ module.exports.pitch = function (remainingRequest) {
1717 return
1818 }
1919
20- // loader.request contains both the resolved loader path and its options
21- // query (e.g. ??ref-0)
22- const toLoaderString = loader => loader . request
20+ const genRequest = loaders => {
21+ // Important: dedupe since both the original rule
22+ // and the cloned rule would match a source import request.
23+ // also make sure to dedupe based on loader path.
24+ // assumes you'd probably never want to apply the same loader on the same
25+ // file twice.
26+ const seen = new Map ( )
27+ const loaderStrings = [ ]
28+
29+ loaders . forEach ( loader => {
30+ const type = typeof loader === 'string' ? loader : loader . path
31+ const request = typeof loader === 'string' ? loader : loader . request
32+ if ( ! seen . has ( type ) ) {
33+ seen . set ( type , true )
34+ // loader.request contains both the resolved loader path and its options
35+ // query (e.g. ??ref-0)
36+ loaderStrings . push ( request )
37+ }
38+ } )
2339
24- const genRequest = loaderStrings => {
25- // important: dedupe
26- loaderStrings = Array . from ( new Set ( loaderStrings ) )
2740 return loaderUtils . stringifyRequest ( this , '-!' + [
2841 ...loaderStrings ,
2942 this . resourcePath + this . resourceQuery
@@ -34,8 +47,8 @@ module.exports.pitch = function (remainingRequest) {
3447 if ( query . type === `style` ) {
3548 const cssLoaderIndex = loaders . findIndex ( l => / ( \/ | \\ ) c s s - l o a d e r / . test ( l . path ) )
3649 if ( cssLoaderIndex ) {
37- const afterLoaders = loaders . slice ( 0 , cssLoaderIndex + 1 ) . map ( toLoaderString )
38- const beforeLoaders = loaders . slice ( cssLoaderIndex + 1 ) . map ( toLoaderString )
50+ const afterLoaders = loaders . slice ( 0 , cssLoaderIndex + 1 )
51+ const beforeLoaders = loaders . slice ( cssLoaderIndex + 1 )
3952 const request = genRequest ( [
4053 ...afterLoaders ,
4154 stylePostLoaderPath ,
@@ -48,10 +61,9 @@ module.exports.pitch = function (remainingRequest) {
4861
4962 // for templates: inject the template compiler
5063 if ( query . type === `template` ) {
51- const beforeLoaders = loaders . map ( toLoaderString )
5264 const request = genRequest ( [
5365 templateLoaderPath + `??vue-loader-options` ,
54- ...beforeLoaders
66+ ...loaders
5567 ] )
5668 // console.log(request)
5769 // the template compiler uses esm exports
@@ -69,6 +81,6 @@ module.exports.pitch = function (remainingRequest) {
6981 // When the user defines a rule that has only resourceQuery but no test,
7082 // both that rule and the cloned rule will match, resulting in duplicated
7183 // loaders. Therefore it is necessary to perform a dedupe here.
72- const request = genRequest ( loaders . map ( toLoaderString ) )
84+ const request = genRequest ( loaders )
7385 return `import mod from ${ request } ; export default mod; export * from ${ request } `
7486}
0 commit comments