@@ -17,13 +17,26 @@ module.exports.pitch = function (remainingRequest) {
17
17
return
18
18
}
19
19
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
+ } )
23
39
24
- const genRequest = loaderStrings => {
25
- // important: dedupe
26
- loaderStrings = Array . from ( new Set ( loaderStrings ) )
27
40
return loaderUtils . stringifyRequest ( this , '-!' + [
28
41
...loaderStrings ,
29
42
this . resourcePath + this . resourceQuery
@@ -34,8 +47,8 @@ module.exports.pitch = function (remainingRequest) {
34
47
if ( query . type === `style` ) {
35
48
const cssLoaderIndex = loaders . findIndex ( l => / ( \/ | \\ ) c s s - l o a d e r / . test ( l . path ) )
36
49
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 )
39
52
const request = genRequest ( [
40
53
...afterLoaders ,
41
54
stylePostLoaderPath ,
@@ -48,10 +61,9 @@ module.exports.pitch = function (remainingRequest) {
48
61
49
62
// for templates: inject the template compiler
50
63
if ( query . type === `template` ) {
51
- const beforeLoaders = loaders . map ( toLoaderString )
52
64
const request = genRequest ( [
53
65
templateLoaderPath + `??vue-loader-options` ,
54
- ...beforeLoaders
66
+ ...loaders
55
67
] )
56
68
// console.log(request)
57
69
// the template compiler uses esm exports
@@ -69,6 +81,6 @@ module.exports.pitch = function (remainingRequest) {
69
81
// When the user defines a rule that has only resourceQuery but no test,
70
82
// both that rule and the cloned rule will match, resulting in duplicated
71
83
// loaders. Therefore it is necessary to perform a dedupe here.
72
- const request = genRequest ( loaders . map ( toLoaderString ) )
84
+ const request = genRequest ( loaders )
73
85
return `import mod from ${ request } ; export default mod; export * from ${ request } `
74
86
}
0 commit comments