Skip to content

Commit 6fa8415

Browse files
authored
feat(varlet-ui): support unplugin-auto-import (unplugin#512)
1 parent ab90643 commit 6fa8415

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/core/resolvers/varlet-ui.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface VarletUIResolverOptions {
99
* @default 'vue3'
1010
*/
1111
version?: 'vue3' | 'vue2'
12+
1213
/**
1314
* import style along with components
1415
*
@@ -23,6 +24,13 @@ export interface VarletUIResolverOptions {
2324
*/
2425
directives?: boolean
2526

27+
/**
28+
* compatible with unplugin-auto-import
29+
*
30+
* @default false
31+
*/
32+
autoImport?: boolean
33+
2634
/**
2735
* @deprecated use `importStyle: 'css'` instead
2836
*/
@@ -34,11 +42,15 @@ export interface VarletUIResolverOptions {
3442
importLess?: boolean
3543
}
3644

45+
const varFunctions = ['Snackbar', 'Picker', 'ActionSheet', 'Dialog', 'Locale', 'StyleProvider']
46+
const varDirectives = ['Ripple', 'Lazy']
47+
3748
export function getResolved(name: string, options: VarletUIResolverOptions): ComponentResolveResult {
3849
const {
3950
importStyle = 'css',
4051
importCss = true,
4152
importLess,
53+
autoImport = false,
4254
version = 'vue3',
4355
} = options
4456

@@ -54,13 +66,11 @@ export function getResolved(name: string, options: VarletUIResolverOptions): Com
5466

5567
return {
5668
from: path,
57-
name: `_${name}Component`,
69+
name: autoImport ? name : `_${name}Component`,
5870
sideEffects,
5971
}
6072
}
6173

62-
const varDirectives = ['Ripple', 'Lazy']
63-
6474
/**
6575
* Resolver for VarletUI
6676
*
@@ -72,6 +82,11 @@ export function VarletUIResolver(options: VarletUIResolverOptions = {}): Compone
7282
{
7383
type: 'component',
7484
resolve: (name: string) => {
85+
const { autoImport = false } = options
86+
87+
if (autoImport && varFunctions.includes(name))
88+
return getResolved(name, options)
89+
7590
if (name.startsWith('Var'))
7691
return getResolved(name.slice(3), options)
7792
},

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy