Skip to content

Commit 4729f3a

Browse files
l1uqiantfu
andauthored
feat(arco): add ArcoResolver exclude to filter components with the sa… (#628)
Co-authored-by: Anthony Fu <[email protected]>
1 parent 56f98aa commit 4729f3a

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/core/resolvers/_utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export function isExclude(name: string, exclude?: string | RegExp | (string | RegExp)[] | undefined): boolean {
2+
if (!exclude)
3+
return false
4+
5+
if (typeof exclude === 'string')
6+
return name === exclude
7+
8+
if (exclude instanceof RegExp)
9+
return !!name.match(exclude)
10+
11+
if (Array.isArray(exclude)) {
12+
for (const item of exclude) {
13+
if (name === item || name.match(item))
14+
return true
15+
}
16+
}
17+
return false
18+
}

src/core/resolvers/arco.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Debug from 'debug'
22
import type { ComponentInfo, ComponentResolver } from '../../types'
33
import { kebabCase, pascalCase } from '../utils'
4+
import { isExclude } from './_utils'
45

56
const debug = Debug('unplugin-vue-components:resolvers:arco')
67

@@ -168,6 +169,12 @@ export type AllowResolveIconOption = true | { enable: true; iconPrefix?: string
168169
export type ResolveIconsOption = DisallowResolveIconOption | AllowResolveIconOption
169170

170171
export interface ArcoResolverOptions {
172+
/**
173+
* exclude components that do not require automatic import
174+
*
175+
* @default []
176+
*/
177+
exclude?: string | RegExp | (string | RegExp)[]
171178
/**
172179
* import style css or less with components
173180
*
@@ -217,7 +224,7 @@ export function ArcoResolver(
217224
}
218225
}
219226
}
220-
if (name.match(/^A[A-Z]/)) {
227+
if (name.match(/^A[A-Z]/) && !isExclude(name, options.exclude)) {
221228
const importStyle = options.importStyle ?? 'css'
222229

223230
const importName = name.slice(1)

src/core/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parse } from 'node:path'
2-
import {minimatch} from 'minimatch'
2+
import { minimatch } from 'minimatch'
33
import resolve from 'resolve'
44
import { slash, toArray } from '@antfu/utils'
55
import {

0 commit comments

Comments
 (0)