feat(@vant/auto-import-resolver): Support exclude in components or apis (#13357)
Co-authored-by: wangzhifeng <wangzhifeng@keytop.com.cn>
This commit is contained in:
@@ -196,3 +196,31 @@ Components({
|
|||||||
- **Default:** `undefined`
|
- **Default:** `undefined`
|
||||||
|
|
||||||
This option is deprecated. Please use the `module` option to set the module type.
|
This option is deprecated. Please use the `module` option to set the module type.
|
||||||
|
|
||||||
|
### exclude
|
||||||
|
|
||||||
|
Set the components or APIs that do not require automatic import.
|
||||||
|
|
||||||
|
- **Type:** `string[]`
|
||||||
|
- **Default:** `[]`
|
||||||
|
- **Example:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
Components({
|
||||||
|
resolvers: [
|
||||||
|
VantResolver({
|
||||||
|
exclude: ['Button'],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
AutoImport({
|
||||||
|
resolvers: [
|
||||||
|
VantResolver({
|
||||||
|
exclude: ['showToast'],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
@@ -196,3 +196,31 @@ Components({
|
|||||||
- **Default:** `undefined`
|
- **Default:** `undefined`
|
||||||
|
|
||||||
此选项已废弃,请使用 `module` 选项来设置模块类型。
|
此选项已废弃,请使用 `module` 选项来设置模块类型。
|
||||||
|
|
||||||
|
### exclude
|
||||||
|
|
||||||
|
设置不自动引入的组件或 API。
|
||||||
|
|
||||||
|
- **Type:** `string[]`
|
||||||
|
- **Default:** `[]`
|
||||||
|
- **Example:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
Components({
|
||||||
|
resolvers: [
|
||||||
|
VantResolver({
|
||||||
|
exclude: ['Button'],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
AutoImport({
|
||||||
|
resolvers: [
|
||||||
|
VantResolver({
|
||||||
|
exclude: ['showToast'],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|||||||
@@ -21,6 +21,13 @@ export interface VantResolverOptions {
|
|||||||
* @deprecated Please use `module` option instead.
|
* @deprecated Please use `module` option instead.
|
||||||
*/
|
*/
|
||||||
ssr?: boolean;
|
ssr?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* exclude components or API that do not require automatic import
|
||||||
|
*
|
||||||
|
* @default []
|
||||||
|
*/
|
||||||
|
exclude?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type VantImportsOptions = Pick<VantResolverOptions, 'module' | 'ssr'>;
|
export type VantImportsOptions = Pick<VantResolverOptions, 'module' | 'ssr'>;
|
||||||
@@ -107,21 +114,23 @@ export function VantResolver(options: VantResolverOptions = {}) {
|
|||||||
resolve: (name: string) => {
|
resolve: (name: string) => {
|
||||||
if (name.startsWith('Van')) {
|
if (name.startsWith('Van')) {
|
||||||
const partialName = name.slice(3);
|
const partialName = name.slice(3);
|
||||||
return {
|
if (!options.exclude?.includes(partialName)) {
|
||||||
name: partialName,
|
return {
|
||||||
from: `vant/${moduleType}`,
|
name: partialName,
|
||||||
sideEffects: getSideEffects(kebabCase(partialName), options),
|
from: `vant/${moduleType}`,
|
||||||
};
|
sideEffects: getSideEffects(kebabCase(partialName), options)
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// import API
|
// import API
|
||||||
if (apiMap.has(name)) {
|
if (apiMap.has(name) && !options.exclude?.includes(name)) {
|
||||||
const partialName = apiMap.get(name)!;
|
const partialName = apiMap.get(name)!;
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
from: `vant/${moduleType}`,
|
from: `vant/${moduleType}`,
|
||||||
sideEffects: getSideEffects(kebabCase(partialName), options),
|
sideEffects: getSideEffects(kebabCase(partialName), options),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user