1
1
import type { ComponentResolver , SideEffectsInfo } from '../../types'
2
2
import { kebabCase } from '../utils'
3
3
4
+ const isServer = Boolean ( process . env . SSR || process . env . SSG || process . env . VITE_SSR || process . env . VITE_SSG )
5
+ const moduleType = isServer ? 'lib' : 'es'
6
+
4
7
export interface VantResolverOptions {
5
8
/**
6
9
* import style css or less along with components
@@ -13,16 +16,16 @@ export interface VantResolverOptions {
13
16
function getSideEffects ( dirName : string , options : VantResolverOptions ) : SideEffectsInfo | undefined {
14
17
const { importStyle = true } = options
15
18
16
- if ( ! importStyle )
19
+ if ( ! importStyle || isServer )
17
20
return
18
21
19
22
if ( importStyle === 'less' )
20
- return `vant/es /${ dirName } /style/less`
23
+ return `vant/${ moduleType } /${ dirName } /style/less`
21
24
22
25
if ( importStyle === 'css' )
23
- return `vant/es /${ dirName } /style/index`
26
+ return `vant/${ moduleType } /${ dirName } /style/index`
24
27
25
- return `vant/es /${ dirName } /style/index`
28
+ return `vant/${ moduleType } /${ dirName } /style/index`
26
29
}
27
30
28
31
/**
@@ -38,7 +41,7 @@ export function VantResolver(options: VantResolverOptions = {}): ComponentResolv
38
41
const partialName = name . slice ( 3 )
39
42
return {
40
43
importName : partialName ,
41
- path : ' vant/es' ,
44
+ path : ` vant/${ moduleType } ` ,
42
45
sideEffects : getSideEffects ( kebabCase ( partialName ) , options ) ,
43
46
}
44
47
}
0 commit comments