Skip to content

Commit 5f156ae

Browse files
committed
refactor: normalize module config
1 parent cb80a9e commit 5f156ae

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

packages/bundler-webpack/src/config/handleModuleVue.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ export const handleModuleVue = ({
2424
isBuild: boolean
2525
isServer: boolean
2626
}): void => {
27-
const applyVuePipeline = ({
28-
rule,
29-
isMd,
27+
const handleVue = ({
28+
lang,
29+
test,
3030
}: {
31-
rule: Config.Rule
32-
isMd: boolean
31+
lang: 'md' | 'vue'
32+
test: RegExp
3333
}): void => {
34+
const rule = config.module.rule(lang).test(test)
35+
3436
// use internal vuepress-ssr-loader to handle SSR dependencies
3537
if (isBuild) {
3638
rule
@@ -50,7 +52,7 @@ export const handleModuleVue = ({
5052
.end()
5153

5254
// use internal vuepress-markdown-loader to handle markdown files
53-
if (isMd) {
55+
if (lang === 'md') {
5456
rule
5557
.use('vuepress-markdown-loader')
5658
.loader(require.resolve('#vuepress-markdown-loader'))
@@ -59,15 +61,8 @@ export const handleModuleVue = ({
5961
}
6062
}
6163

62-
applyVuePipeline({
63-
rule: config.module.rule('md').test(/\.md$/),
64-
isMd: true,
65-
})
66-
67-
applyVuePipeline({
68-
rule: config.module.rule('vue').test(/\.vue$/),
69-
isMd: false,
70-
})
64+
handleVue({ lang: 'md', test: /\.md$/ })
65+
handleVue({ lang: 'vue', test: /\.vue$/ })
7166

7267
// use vue-loader plugin
7368
config.plugin('vue-loader').use(VueLoaderPlugin)

0 commit comments

Comments
 (0)