Skip to content

Commit 8631046

Browse files
authored
fix(resolvers): fix library vant style sideEffects (#234)
1 parent 1455aad commit 8631046

File tree

3 files changed

+52
-52
lines changed

3 files changed

+52
-52
lines changed

examples/vite-vue3/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"build": "cross-env DEBUG=unplugin-vue-components:* vite build"
88
},
99
"dependencies": {
10-
"vant": "^3.2.1"
10+
"vant": "^3.3.6"
1111
},
1212
"devDependencies": {
1313
"@iconify/json": "^1.1.396",

pnpm-lock.yaml

Lines changed: 32 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/resolvers/vant.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1-
import { ComponentResolver } from '../../types'
1+
import { ComponentResolver, SideEffectsInfo } from '../../types'
22
import { kebabCase } from '../utils'
33

44
export interface VantResolverOptions {
55
/**
6-
* import style along with components
6+
* import style css or less along with components
77
*
88
* @default true
99
*/
10-
importStyle?: boolean
10+
importStyle?: boolean | 'css' | 'less'
11+
}
12+
13+
function getSideEffects(dirName: string, options: VantResolverOptions): SideEffectsInfo | undefined {
14+
const { importStyle = true } = options
15+
16+
if (!importStyle)
17+
return
18+
19+
if (importStyle === 'less')
20+
return `vant/es/${dirName}/style/less`
21+
22+
if (importStyle === 'css')
23+
return `vant/es/${dirName}/style/index`
24+
25+
return `vant/es/${dirName}/style/index`
1126
}
1227

1328
/**
@@ -19,14 +34,12 @@ export function VantResolver(options: VantResolverOptions = {}): ComponentResolv
1934
return {
2035
type: 'component',
2136
resolve: (name: string) => {
22-
const { importStyle = true } = options
23-
2437
if (name.startsWith('Van')) {
2538
const partialName = name.slice(3)
2639
return {
2740
importName: partialName,
2841
path: 'vant/es',
29-
sideEffects: importStyle ? `vant/es/${kebabCase(partialName)}/style` : undefined,
42+
sideEffects: getSideEffects(kebabCase(partialName), options),
3043
}
3144
}
3245
},

0 commit comments

Comments
 (0)