1
1
import * as qs from 'querystring'
2
- import webpack = require ( 'webpack' )
2
+ import type { Compiler , RuleSetRule } from 'webpack'
3
3
import type { VueLoaderOptions } from './'
4
4
import { clientCache , typeDepToSFCMap } from './resolveScript'
5
5
import fs = require( 'fs' )
@@ -11,10 +11,19 @@ const RuleSet = require('webpack/lib/RuleSet')
11
11
const id = 'vue-loader-plugin'
12
12
const NS = 'vue-loader'
13
13
14
+ // these types are no longer available in webpack 5
15
+ type RuleSetQuery = string | { [ k : string ] : any }
16
+ interface RuleSetLoader {
17
+ loader ?: string | undefined
18
+ options ?: RuleSetQuery | undefined
19
+ ident ?: string | undefined
20
+ query ?: RuleSetQuery | undefined
21
+ }
22
+
14
23
class VueLoaderPlugin {
15
24
static NS = NS
16
25
17
- apply ( compiler : webpack . Compiler ) {
26
+ apply ( compiler : Compiler ) {
18
27
// inject NS for plugin installation check in the main loader
19
28
compiler . hooks . compilation . tap ( id , ( compilation ) => {
20
29
compilation . hooks . normalModuleLoader . tap ( id , ( loaderContext : any ) => {
@@ -24,7 +33,7 @@ class VueLoaderPlugin {
24
33
25
34
const rawRules = compiler . options . module ! . rules
26
35
// use webpack's RuleSet utility to normalize user rules
27
- const rules = new RuleSet ( rawRules ) . rules as webpack . RuleSetRule [ ]
36
+ const rules = new RuleSet ( rawRules ) . rules as RuleSetRule [ ]
28
37
29
38
// find the rule that applies to vue files
30
39
let vueRuleIndex = rawRules . findIndex ( createMatcher ( `foo.vue` ) )
@@ -47,7 +56,7 @@ class VueLoaderPlugin {
47
56
}
48
57
49
58
// get the normlized "use" for vue files
50
- const vueUse = vueRule . use as webpack . RuleSetLoader [ ]
59
+ const vueUse = vueRule . use as RuleSetLoader [ ]
51
60
// get vue-loader options
52
61
const vueLoaderUseIndex = vueUse . findIndex ( ( u ) => {
53
62
// FIXME: this code logic is incorrect when project paths starts with `vue-loader-something`
@@ -171,7 +180,7 @@ class VueLoaderPlugin {
171
180
}
172
181
173
182
function createMatcher ( fakeFile : string ) {
174
- return ( rule : webpack . RuleSetRule ) => {
183
+ return ( rule : RuleSetRule ) => {
175
184
// #1201 we need to skip the `include` check when locating the vue rule
176
185
const clone = Object . assign ( { } , rule )
177
186
delete clone . include
@@ -180,7 +189,7 @@ function createMatcher(fakeFile: string) {
180
189
}
181
190
}
182
191
183
- function cloneRule ( rule : webpack . RuleSetRule ) {
192
+ function cloneRule ( rule : RuleSetRule ) {
184
193
const resource = rule . resource as Function
185
194
const resourceQuery = rule . resourceQuery as Function
186
195
// Assuming `test` and `resourceQuery` tests are executed in series and
@@ -225,7 +234,7 @@ function cloneRule(rule: webpack.RuleSetRule) {
225
234
return res
226
235
}
227
236
228
- function cloneRuleForRenderFn ( rule : webpack . RuleSetRule ) {
237
+ function cloneRuleForRenderFn ( rule : RuleSetRule ) {
229
238
const resource = rule . resource as Function
230
239
const resourceQuery = rule . resourceQuery as Function
231
240
let currentResource : string
0 commit comments