auth.andert.me/vite.config.ts
2023-07-22 09:29:40 +02:00

32 lines
768 B
TypeScript

import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import * as fs from 'fs';
import { resolve } from 'path';
export default defineConfig({
plugins: [
sveltekit(),
{
name: 'components-resolver',
resolveId(source) {
if (source === 'virtual:components-list') return source;
return null;
},
load(id) {
if (id === 'virtual:components-list') {
const componentsDir = resolve(__dirname, 'src/lib/components');
const components = fs.readdirSync(componentsDir)
.filter(f => f.endsWith('.svelte'))
.map(f => f.replace('.svelte', ''));
return `export default ${JSON.stringify(components)};`;
}
return null;
}
}
],
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
}
});