mirror of
https://github.com/youzan/vant.git
synced 2025-10-18 01:17:15 +00:00
feat: support unplugin-auto-import plugin (#12679)
This commit is contained in:
@@ -56,8 +56,48 @@ function getSideEffects(dirName: string, options: VantResolverOptions) {
|
||||
return `vant/${moduleType}/${dirName}/style/index`;
|
||||
}
|
||||
|
||||
function getAPIMap() {
|
||||
const apiMap = new Map<string, string>();
|
||||
|
||||
const api = {
|
||||
dialog: [
|
||||
'showDialog',
|
||||
'closeDialog',
|
||||
'showConfirmDialog',
|
||||
'setDialogDefaultOptions',
|
||||
'resetDialogDefaultOptions',
|
||||
],
|
||||
imagePreview: ['showImagePreview'],
|
||||
notify: [
|
||||
'showNotify',
|
||||
'closeNotify',
|
||||
'setNotifyDefaultOptions',
|
||||
'resetNotifyDefaultOptions',
|
||||
],
|
||||
toast: [
|
||||
'showToast',
|
||||
'closeToast',
|
||||
'showFailToast',
|
||||
'showLoadingToast',
|
||||
'showSuccessToast',
|
||||
'allowMultipleToast',
|
||||
'setToastDefaultOptions',
|
||||
'resetToastDefaultOptions',
|
||||
],
|
||||
};
|
||||
|
||||
Object.entries(api).forEach(([importName, apiList]) => {
|
||||
apiList.forEach((api) => {
|
||||
apiMap.set(api, importName);
|
||||
});
|
||||
});
|
||||
|
||||
return apiMap;
|
||||
}
|
||||
|
||||
export function VantResolver(options: VantResolverOptions = {}) {
|
||||
const moduleType = getModuleType(options);
|
||||
const apiMap = getAPIMap();
|
||||
|
||||
return {
|
||||
type: 'component' as const,
|
||||
@@ -71,6 +111,16 @@ export function VantResolver(options: VantResolverOptions = {}) {
|
||||
sideEffects: getSideEffects(kebabCase(partialName), options),
|
||||
};
|
||||
}
|
||||
|
||||
// import API
|
||||
if (apiMap.has(name)) {
|
||||
const partialName = apiMap.get(name)!;
|
||||
return {
|
||||
name,
|
||||
from: `vant/${moduleType}`,
|
||||
sideEffects: getSideEffects(kebabCase(partialName), options),
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user