| 1 | import type { ResolvedSlidevOptions, SlidevPluginOptions } from '@slidev/types' |
| 2 | import { existsSync } from 'node:fs' |
| 3 | import { join } from 'pathe' |
| 4 | |
| 5 | export async function createStaticCopyPlugin( |
| 6 | { themeRoots, addonRoots }: ResolvedSlidevOptions, |
| 7 | pluginOptions: SlidevPluginOptions, |
| 8 | ) { |
| 9 | const publicDirs = [...themeRoots, ...addonRoots].map(i => join(i, 'public')).filter(existsSync) |
| 10 | if (!publicDirs.length) |
| 11 | return |
| 12 | const { viteStaticCopy } = await import('vite-plugin-static-copy') |
| 13 | return viteStaticCopy({ |
| 14 | silent: true, |
| 15 | targets: publicDirs.map(dir => ({ |
| 16 | src: `${dir}/*`, |
| 17 | dest: 'theme', |
| 18 | })), |
| 19 | ...pluginOptions.staticCopy, |
| 20 | }) |
| 21 | } |
| 22 |