diff --git a/src/core/resolvers/_utils.ts b/src/core/resolvers/_utils.ts new file mode 100644 index 00000000..3c907ac3 --- /dev/null +++ b/src/core/resolvers/_utils.ts @@ -0,0 +1,18 @@ +export function isExclude(name: string, exclude?: string | RegExp | (string | RegExp)[] | undefined): boolean { + if (!exclude) + return false + + if (typeof exclude === 'string') + return name === exclude + + if (exclude instanceof RegExp) + return !!name.match(exclude) + + if (Array.isArray(exclude)) { + for (const item of exclude) { + if (name === item || name.match(item)) + return true + } + } + return false +} diff --git a/src/core/resolvers/arco.ts b/src/core/resolvers/arco.ts index d7dae494..5c31aaf0 100644 --- a/src/core/resolvers/arco.ts +++ b/src/core/resolvers/arco.ts @@ -1,6 +1,7 @@ import Debug from 'debug' import type { ComponentInfo, ComponentResolver } from '../../types' import { kebabCase, pascalCase } from '../utils' +import { isExclude } from './_utils' const debug = Debug('unplugin-vue-components:resolvers:arco') @@ -168,6 +169,12 @@ export type AllowResolveIconOption = true | { enable: true; iconPrefix?: string export type ResolveIconsOption = DisallowResolveIconOption | AllowResolveIconOption export interface ArcoResolverOptions { + /** + * exclude components that do not require automatic import + * + * @default [] + */ + exclude?: string | RegExp | (string | RegExp)[] /** * import style css or less with components * @@ -217,7 +224,7 @@ export function ArcoResolver( } } } - if (name.match(/^A[A-Z]/)) { + if (name.match(/^A[A-Z]/) && !isExclude(name, options.exclude)) { const importStyle = options.importStyle ?? 'css' const importName = name.slice(1) diff --git a/src/core/utils.ts b/src/core/utils.ts index 22ac7adf..5e5ae49f 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -1,5 +1,5 @@ import { parse } from 'node:path' -import {minimatch} from 'minimatch' +import { minimatch } from 'minimatch' import resolve from 'resolve' import { slash, toArray } from '@antfu/utils' import {