Files
gpx.studio/website/vite.config.ts
T

50 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-04-03 16:13:42 +02:00
import { sveltekit } from '@sveltejs/kit/vite';
2024-07-05 17:13:19 +02:00
import { enhancedImages } from '@sveltejs/enhanced-img';
2026-10-18 16:53:39 +02:00
import { defineConfig, type Plugin } from 'vite';
2025-06-21 21:07:36 +02:00
import tailwindcss from '@tailwindcss/vite';
2026-07-14 18:36:30 +02:00
import wasm from 'vite-plugin-wasm';
2024-04-03 16:13:42 +02:00
2026-10-18 16:53:39 +02:00
/** Whether the website is built for the desktop app (`npm run build:desktop`), which only has the app. */
const desktop = process.env.BUILD_TARGET === 'desktop';
/** The pages of the website, which the desktop app opens on gpx.studio: home, help and embed. */
const websitePage = /\/src\/routes\/\[\[language\]\]\/(\+page\.|help\/|embed\/)/;
/** The help guides, which the server imports too (for the titles of the pages). */
const guide = /\/src\/lib\/docs\/.*\.mdx$/;
/**
* For the desktop app, empties the pages of the website, the help guides and the WebAssembly engine
* (the app has its own), so that their code, images and the module are not in the build.
*/
function desktopBuild(): Plugin {
return {
name: 'desktop-build',
enforce: 'pre',
load(id) {
const path = id.split('?')[0];
if (websitePage.test(path)) {
// no entries: the page is not prerendered
return path.endsWith('.server.ts') ? 'export const entries = () => [];' : '';
}
if (guide.test(path)) {
return "---\ntitle: ''\n---\n";
}
if (path.endsWith('/src/lib/engine/backend/wasm.ts')) {
return `export async function createWasmBackend() {
throw new Error('The desktop app has no WebAssembly engine');
}`;
}
},
};
}
2024-04-03 16:13:42 +02:00
export default defineConfig({
2026-10-18 16:53:39 +02:00
plugins: [
...(desktop ? [desktopBuild()] : []),
enhancedImages(),
tailwindcss(),
wasm(),
sveltekit(),
],
2024-04-03 16:13:42 +02:00
});