@@ -15,19 +15,20 @@ module.exports = class VueLoaderPlugin {
15
15
const clone = Object . assign ( { } , rule )
16
16
delete clone . include
17
17
const normalized = RuleSet . normalizeRule ( clone )
18
- return ! rule . enforce && normalized . resource ( `foo.vue` )
18
+ return ! rule . enforce && normalized . resource && normalized . resource ( `foo.vue` )
19
19
} )
20
20
const vueRule = rawRules [ vueRuleIndex ]
21
21
22
22
if ( ! vueRule ) {
23
23
throw new Error (
24
- `VueLoaderPlugin Error: no matching rule for vue files are found.`
24
+ `[VueLoaderPlugin Error] No matching rule for .vue files found.\n` +
25
+ `Make sure there is at least one root-level rule that matches .vue files.`
25
26
)
26
27
}
27
28
28
29
if ( vueRule . oneOf ) {
29
30
throw new Error (
30
- `vue-loader 15 currently does not support vue rules with oneOf.`
31
+ `[VueLoaderPlugin Error] vue-loader 15 currently does not support vue rules with oneOf.`
31
32
)
32
33
}
33
34
@@ -42,7 +43,8 @@ module.exports = class VueLoaderPlugin {
42
43
43
44
if ( vueLoaderUseIndex < 0 ) {
44
45
throw new Error (
45
- `VueLoaderPlugin Error: no matching use for vue-loader is found.`
46
+ `[VueLoaderPlugin Error] No matching use for vue-loader is found.\n` +
47
+ `Make sure the rule matching .vue files include vue-loader in its use.`
46
48
)
47
49
}
48
50
@@ -78,31 +80,19 @@ module.exports = class VueLoaderPlugin {
78
80
const baseRules = rawRules . filter ( r => r !== vueRule )
79
81
const normalizedRules = rawNormalizedRules . filter ( r => r !== normalizedVueRule )
80
82
81
- const customFallbackRule = {
82
- loader : require . resolve ( './loaders/noop' ) ,
83
- resourceQuery : / t y p e = c u s t o m /
84
- }
85
-
86
- // construct a new rule for vue file, with oneOf containing
87
- // multiple rules with dynamic resourceQuery functions that applies to
88
- // different language blocks in a raw vue file.
89
- const constructedRule = {
90
- test : / \. v u e $ / ,
91
- oneOf : baseRules . map ( ( rule , i ) => {
92
- // for each user rule, create a cloned rule by checking if the rule
93
- // matches the lang specified in the resourceQuery.
94
- return cloneRule ( rule , normalizedRules [ i ] , normalizedVueUse )
95
- } ) . concat ( customFallbackRule , vueRule )
96
- }
97
-
98
- // replace the original vue rule with our new constructed rule.
99
- rawRules . splice ( vueRuleIndex , 1 , constructedRule )
83
+ // for each user rule, inject a cloned rule by checking if the rule
84
+ // matches the lang specified in the resourceQuery.
85
+ rawRules . unshift . apply ( rawRules , baseRules . map ( ( rule , i ) => {
86
+ return cloneRule ( rule , normalizedRules [ i ] , normalizedVueUse )
87
+ } ) )
100
88
101
89
// inject global pitcher (responsible for injecting template compiler
102
90
// loader & CSS post loader)
103
91
rawRules . unshift ( {
104
92
loader : require . resolve ( './loaders/pitch' )
105
93
} )
94
+
95
+ // console.log(rawRules)
106
96
}
107
97
}
108
98
@@ -116,7 +106,7 @@ function cloneRule (rule, normalizedRule, vueUse) {
116
106
const res = Object . assign ( { } , rule , {
117
107
test : resource => {
118
108
currentResource = resource
119
- return true
109
+ return / \. v u e $ / . test ( resource )
120
110
} ,
121
111
resourceQuery : query => {
122
112
const parsed = qs . parse ( query . slice ( 1 ) )
@@ -133,12 +123,13 @@ function cloneRule (rule, normalizedRule, vueUse) {
133
123
}
134
124
return true
135
125
} ,
136
- use : [
137
- ...( normalizedRule . use || [ ] ) . map ( cleanUse ) ,
138
- ...rule . oneOf ? [ ] : vueUse
139
- ]
126
+ use : ( normalizedRule . use || [ ] ) . map ( cleanUse )
140
127
} )
141
128
129
+ if ( ! res . use . length ) {
130
+ delete res . use
131
+ }
132
+
142
133
// delete shorthand since we have normalized use
143
134
delete res . loader
144
135
delete res . options
0 commit comments