tiny-vue/internals/unplugin-tiny-vue/src/index.ts

38 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import AutoVite from 'unplugin-vue-components/vite'
import AutoWebpack from 'unplugin-vue-components/webpack'
import AutoRollup from 'unplugin-vue-components/rollup'
import AutoEsbuild from 'unplugin-vue-components/esbuild'
import AutoRspack from 'unplugin-vue-components/rspack'
const supportMap = {
'vite': AutoVite,
'webpack': AutoWebpack,
'rollup': AutoRollup,
'esbuild': AutoEsbuild,
'rspack': AutoRspack
}
export const TinyVueResolver = (componentName) => {
if (componentName.startsWith('Tiny') && !componentName.startsWith('TinyIcon')) {
return {
name: componentName.slice(4),
from: '@opentiny/vue'
}
}
}
/** TinyVue 自动导入组件的插件支持Vite,Webpack,Rollup 等常见的构建工具。
* 目前不支持Tiny Icon的自动导入
* @example
* import autoImportPlugin from '@opentiny/unplugin-tiny-vue'
* plugins: [autoImportPlugin('vite')]
*/
export default (name) => {
// 兼容webpack/vite的差异
const autoPlugin = supportMap[name].default || supportMap[name]
return autoPlugin({
resolvers: [TinyVueResolver]
})
}