1
1
import { createRequire } from 'node:module'
2
+ import type { App } from '@vuepress/core'
2
3
import type { VueLoaderOptions } from 'vue-loader'
3
4
import { VueLoaderPlugin } from 'vue-loader'
4
5
import type Config from 'webpack-5-chain'
6
+ import type { VuepressMarkdownLoaderOptions } from '../loaders/vuepressMarkdownLoader'
5
7
import type { WebpackBundlerOptions } from '../types.js'
6
8
7
9
const require = createRequire ( import . meta. url )
@@ -10,26 +12,62 @@ const require = createRequire(import.meta.url)
10
12
* Set webpack module to handle vue files
11
13
*/
12
14
export const handleModuleVue = ( {
15
+ app,
13
16
options,
14
17
config,
18
+ isBuild,
15
19
isServer,
16
20
} : {
21
+ app : App
17
22
options : WebpackBundlerOptions
18
23
config : Config
24
+ isBuild : boolean
19
25
isServer : boolean
20
26
} ) : void => {
21
- // .vue files
22
- config . module
23
- . rule ( 'vue' )
24
- . test ( / \. v u e $ / )
25
- // use vue-loader
26
- . use ( 'vue-loader' )
27
- . loader ( require . resolve ( 'vue-loader' ) )
28
- . options ( {
29
- ...options . vue ,
30
- isServerBuild : isServer ,
31
- } as VueLoaderOptions )
32
- . end ( )
27
+ const applyVuePipeline = ( {
28
+ rule,
29
+ isMd,
30
+ } : {
31
+ rule : Config . Rule
32
+ isMd : boolean
33
+ } ) : void => {
34
+ // use internal vuepress-ssr-loader to handle SSR dependencies
35
+ if ( isBuild ) {
36
+ rule
37
+ . use ( 'vuepress-ssr-loader' )
38
+ . loader ( require . resolve ( '#vuepress-ssr-loader' ) )
39
+ . end ( )
40
+ }
41
+
42
+ // use official vue-loader
43
+ rule
44
+ . use ( 'vue-loader' )
45
+ . loader ( require . resolve ( 'vue-loader' ) )
46
+ . options ( {
47
+ ...options . vue ,
48
+ isServerBuild : isServer ,
49
+ } satisfies VueLoaderOptions )
50
+ . end ( )
51
+
52
+ // use internal vuepress-markdown-loader to handle markdown files
53
+ if ( isMd ) {
54
+ rule
55
+ . use ( 'vuepress-markdown-loader' )
56
+ . loader ( require . resolve ( '#vuepress-markdown-loader' ) )
57
+ . options ( { app } satisfies VuepressMarkdownLoaderOptions )
58
+ . end ( )
59
+ }
60
+ }
61
+
62
+ applyVuePipeline ( {
63
+ rule : config . module . rule ( 'md' ) . test ( / \. m d $ / ) ,
64
+ isMd : true ,
65
+ } )
66
+
67
+ applyVuePipeline ( {
68
+ rule : config . module . rule ( 'vue' ) . test ( / \. v u e $ / ) ,
69
+ isMd : false ,
70
+ } )
33
71
34
72
// use vue-loader plugin
35
73
config . plugin ( 'vue-loader' ) . use ( VueLoaderPlugin )
0 commit comments