diff --git a/sites/svelte.dev/src/routes/docs/+server.js b/sites/svelte.dev/src/routes/docs/+server.js index 19b3acd3e6..41eb6db642 100644 --- a/sites/svelte.dev/src/routes/docs/+server.js +++ b/sites/svelte.dev/src/routes/docs/+server.js @@ -1,4 +1,5 @@ -import js from './redirect.js?raw'; +// @ts-expect-error custom suffix doesn't have types +import js from './redirect.js?minified'; // prerenderer will choke otherwise export const prerender = false; diff --git a/sites/svelte.dev/vite.config.js b/sites/svelte.dev/vite.config.js index c02c0d66a8..908226d094 100644 --- a/sites/svelte.dev/vite.config.js +++ b/sites/svelte.dev/vite.config.js @@ -2,8 +2,26 @@ import { sveltekit } from '@sveltejs/kit/vite'; import { browserslistToTargets } from 'lightningcss'; import { readFile } from 'node:fs/promises'; import browserslist from 'browserslist'; +import { transformWithEsbuild } from 'vite'; -const plugins = [raw(['.ttf']), sveltekit()]; +/** @type {import('vite').Plugin[]} */ +const plugins = [ + raw(['.ttf']), + sveltekit(), + { + name: 'minified-raw-js', + + async load(id) { + if (id.endsWith('.js?minified')) { + const file = id.replace('?minified', ''); + let code = await readFile(file, 'utf-8'); + return `export default ${JSON.stringify( + (await transformWithEsbuild(code, file, { minify: true, format: 'esm' })).code + )}`; + } + } + } +]; // Only enable sharp if we're not in a webcontainer env if (!process.versions.webcontainer) {