fix vite config

This commit is contained in:
“chrisshank” 2024-12-11 16:06:58 -08:00
parent 2fccf42c9e
commit 3623702b79
2 changed files with 10 additions and 8 deletions

View File

@ -89,7 +89,6 @@
}); });
document.addEventListener('click', (event) => { document.addEventListener('click', (event) => {
console.log(event.target);
if (event.target === document.body || event.target === projector) { if (event.target === document.body || event.target === projector) {
projector.project(); projector.project();
} }

View File

@ -4,18 +4,16 @@ import { defineConfig, IndexHtmlTransformContext, Plugin } from 'vite';
const demoDir = resolve(__dirname, 'demo'); const demoDir = resolve(__dirname, 'demo');
const files: string[] = readdirSync(demoDir).filter((file) => file.endsWith('.html')); function getFiles() {
const input: Record<string, string> = files.reduce((acc, file) => { return readdirSync(demoDir).filter((file) => file.endsWith('.html'));
acc[file.replace('.html', '')] = resolve(demoDir, file); }
return acc;
}, {} as Record<string, string>);
const linkGenerator = (): Plugin => { const linkGenerator = (): Plugin => {
return { return {
name: 'link-generator', name: 'link-generator',
transformIndexHtml(html: string, ctx: IndexHtmlTransformContext) { transformIndexHtml(html: string, ctx: IndexHtmlTransformContext) {
if (!ctx.filename.endsWith('index.html')) return; if (!ctx.filename.endsWith('index.html')) return;
const files = getFiles();
// First, handle ungrouped files // First, handle ungrouped files
const ungroupedFiles = files.filter( const ungroupedFiles = files.filter(
(file) => !file.includes('index') && !file.startsWith('_') && !file.match(/^\[([^\]]+)\]/) (file) => !file.includes('index') && !file.startsWith('_') && !file.match(/^\[([^\]]+)\]/)
@ -70,7 +68,12 @@ export default defineConfig({
plugins: [linkGenerator()], plugins: [linkGenerator()],
build: { build: {
target: 'esnext', target: 'esnext',
rollupOptions: { input }, rollupOptions: {
input: getFiles().reduce((acc, file) => {
acc[file.replace('.html', '')] = resolve(demoDir, file);
return acc;
}, {} as Record<string, string>),
},
modulePreload: { modulePreload: {
polyfill: false, polyfill: false,
}, },