Skip to content

Commit dba0e43

Browse files
committed
feat: dispatch plugin dynammically
1 parent 9de36af commit dba0e43

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

Diff for: src/plugin.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
import webpack from 'webpack'
21
import type { Compiler } from 'webpack'
32

43
declare class VueLoaderPlugin {
54
static NS: string
65
apply(compiler: Compiler): void
76
}
87

9-
let Plugin: typeof VueLoaderPlugin
8+
const NS = 'vue-loader'
109

11-
if (webpack.version && webpack.version[0] > '4') {
12-
// webpack5 and upper
13-
Plugin = require('./pluginWebpack5').default
14-
} else {
15-
// webpack4 and lower
16-
Plugin = require('./pluginWebpack4').default
10+
class Plugin {
11+
static NS = NS
12+
apply(compiler: Compiler) {
13+
let Ctor: typeof VueLoaderPlugin
14+
if (compiler.webpack?.version && compiler.webpack.version[0] > '4') {
15+
// webpack5 and upper
16+
Ctor = require('./pluginWebpack5').default
17+
} else {
18+
// webpack4 and lower
19+
Ctor = require('./pluginWebpack4').default
20+
}
21+
new Ctor().apply(compiler)
22+
}
1723
}
1824

1925
export default Plugin

0 commit comments

Comments
 (0)