返回 slidev
components.ts
根目录 / packages / slidev / node / vite / components.ts
1 import type { ResolvedSlidevOptions, SlidevPluginOptions } from '@slidev/types'
2 import { join } from 'pathe'
3 import IconsResolver from 'unplugin-icons/resolver'
4 import Components from 'unplugin-vue-components/vite'
5
6 const RE_VUE_EXT = /\.vue$/
7 const RE_VUE_QUERY_VUE = /\.vue\?vue/
8 const RE_VUE_QUERY_V = /\.vue\?v=/
9 const RE_MD_EXT = /\.md$/
10 const RE_MD_QUERY_VUE = /\.md\?vue/
11
12 export function createComponentsPlugin(
13 { clientRoot, roots }: ResolvedSlidevOptions,
14 pluginOptions: SlidevPluginOptions,
15 ) {
16 return Components({
17 extensions: ['vue', 'md', 'js', 'ts', 'jsx', 'tsx'],
18
19 dirs: [
20 join(clientRoot, 'builtin'),
21 ...roots.map(i => join(i, 'components')),
22 ],
23 globsExclude: [],
24
25 include: [RE_VUE_EXT, RE_VUE_QUERY_VUE, RE_VUE_QUERY_V, RE_MD_EXT, RE_MD_QUERY_VUE],
26 exclude: [],
27
28 resolvers: [
29 IconsResolver({
30 prefix: '',
31 customCollections: Object.keys(pluginOptions.icons?.customCollections || []),
32 }),
33 ],
34
35 dts: false,
36
37 ...pluginOptions.components,
38 })
39 }
40
40 lines TYPESCRIPT