diff --git a/demo/index.html b/demo/index.html index b177742..20782d5 100644 --- a/demo/index.html +++ b/demo/index.html @@ -16,26 +16,10 @@ -

Folk Canvas Primitives

+

Folk Canvas Demos

diff --git a/demo/vite.config.ts b/demo/vite.config.ts index 13ba4fd..5f3fffe 100644 --- a/demo/vite.config.ts +++ b/demo/vite.config.ts @@ -1,18 +1,39 @@ import { resolve } from 'node:path'; import { readdirSync } from 'node:fs'; -import { defineConfig } from 'vite'; +import { defineConfig, IndexHtmlTransformContext, Plugin } from 'vite'; + +const files: string[] = readdirSync(__dirname).filter((file) => file.endsWith('.html')); + +const input: Record = files.reduce((acc, file) => { + acc[file.replace('.html', '')] = resolve(__dirname, file); + return acc; +}, {} as Record); + +const linkGenerator = (): Plugin => { + return { + name: 'link-generator', + transformIndexHtml(html: string, ctx: IndexHtmlTransformContext) { + if (!ctx.filename.endsWith('index.html')) return; + + const links = files + .filter((file) => !file.includes('index')) + .sort() + .map((file) => { + const title = file.replace('.html', '').replaceAll('-', ' '); + return `
  • ${title}
  • `; + }) + .join('\n'); + + return html.replace('{{ LINKS }}', links); + }, + }; +}; export default defineConfig({ + plugins: [linkGenerator()], build: { target: 'esnext', - rollupOptions: { - input: readdirSync(__dirname) - .filter((file) => file.endsWith('.html')) - .reduce((acc, file) => { - acc[file.replace('.html', '')] = resolve(__dirname, file); - return acc; - }, {} as Record), - }, + rollupOptions: { input }, modulePreload: { polyfill: false, },