mirror of
https://github.com/sunniejs/vue-h5-template.git
synced 2025-04-05 19:42:08 +08:00
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
/**
|
|
* @name AutoRegistryComponents
|
|
* @description 按需加载,自动引入组件
|
|
*/
|
|
|
|
import Components from 'unplugin-vue-components/vite';
|
|
import { VueUseComponentsResolver, VantResolver, VarletUIResolver } from 'unplugin-vue-components/resolvers';
|
|
|
|
const NutUIResolver = () => {
|
|
return (name) => {
|
|
if (name.startsWith('Nut')) {
|
|
const partialName = name.slice(3);
|
|
return {
|
|
name: partialName,
|
|
from: '@nutui/nutui',
|
|
sideEffects: `@nutui/nutui/dist/packages/${partialName.toLowerCase()}/style`,
|
|
};
|
|
}
|
|
};
|
|
};
|
|
|
|
export const AutoRegistryComponents = () => {
|
|
return Components({
|
|
// dirs: ['src/components'],
|
|
extensions: ['vue', 'md'],
|
|
deep: true,
|
|
dts: 'types/components.d.ts',
|
|
directoryAsNamespace: false,
|
|
globalNamespaces: [],
|
|
directives: true,
|
|
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
|
|
exclude: [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/],
|
|
resolvers: [VueUseComponentsResolver(), VantResolver(), VarletUIResolver(), NutUIResolver()],
|
|
});
|
|
};
|