You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DateKeys-App/vite.config.ts

54 lines
2.0 KiB

// Vite configuration of the SvelteKit site. The library tests run with
// vitest.config.ts, which vitest prefers when both files exist.
import { sveltekit } from '@sveltejs/kit/vite';
import { mkdirSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { defineConfig, type Plugin } from 'vite';
// Records what the client bundle is made of, for scripts/check-build.mjs:
// each chunk with the chunks it imports and the modules it contains, with
// their rendered sizes. The record goes to .svelte-kit/output, outside the
// site.
function clientModules(): Plugin {
let root = process.cwd();
return {
name: 'datekeys:client-modules',
apply: 'build',
configResolved(config) {
root = config.root;
},
generateBundle(_, bundle) {
if (this.environment.name !== 'client') return;
const chunks: Record<string, { imports: string[]; dynamicImports: string[]; modules: Record<string, number> }> = {};
for (const out of Object.values(bundle)) {
if (out.type !== 'chunk') continue;
chunks[out.fileName] = {
imports: out.imports,
dynamicImports: out.dynamicImports,
modules: Object.fromEntries(Object.entries(out.modules).map(([id, m]) => [id.replace(/\\/g, '/'), m.renderedLength])),
};
}
const dir = join(root, '.svelte-kit', 'output');
mkdirSync(dir, { recursive: true });
writeFileSync(join(dir, 'client-modules.json'), JSON.stringify({ chunks }, null, 1));
},
};
}
export default defineConfig({
plugins: [sveltekit(), clientModules()],
build: {
// Never inline an asset as a data: URL. The CSP allows only the page's
// own origin, so the official fixtures (src/lib/inspector/fixtures.ts)
// must be separate same-origin files, whatever their size.
assetsInlineLimit: 0,
},
server: {
fs: {
// The dev server serves the official fixtures straight from testdata/,
// the single source of truth; the build copies them as hashed assets.
allow: ['testdata/fixtures'],
},
},
});

Powered by TurnKey Linux.