sparse desktop build

This commit is contained in:
vcoppe committed 2026-10-18 16:53:39 +02:00
1 parent 6556c29492
commit 741d35db1e
5 files changed
+57 -5

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
"build": { "build": {
"beforeDevCommand": "npm --prefix ../website run dev -- --port 4283", "beforeDevCommand": "npm --prefix ../website run dev -- --port 4283",
"devUrl": "http://localhost:4283", "devUrl": "http://localhost:4283",
"beforeBuildCommand": "BASE_PATH='' npm --prefix ../website run build", "beforeBuildCommand": "npm --prefix ../website run build:desktop",
"frontendDist": "../website/build" "frontendDist": "../website/build"
}, },
"app": { "app": {
+1
View File
@@ -5,6 +5,7 @@
"scripts": { "scripts": {
"dev": "vite dev", "dev": "vite dev",
"build": "vite build", "build": "vite build",
"build:desktop": "BUILD_TARGET=desktop BASE_PATH='' vite build",
"prebuild": "npx tsx src/lib/scripts/pwa-manifest.ts", "prebuild": "npx tsx src/lib/scripts/pwa-manifest.ts",
"postbuild": "npx tsx src/lib/scripts/sitemap.ts", "postbuild": "npx tsx src/lib/scripts/sitemap.ts",
"preview": "vite preview", "preview": "vite preview",
+6 -1
View File
@@ -46,8 +46,13 @@ export async function handle({ event, resolve }) {
<meta name="twitter:url" content="https://gpx.studio/" /> <meta name="twitter:url" content="https://gpx.studio/" />
<meta name="twitter:site" content="@gpxstudio" /> <meta name="twitter:site" content="@gpxstudio" />
<meta name="twitter:creator" content="@gpxstudio" /> <meta name="twitter:creator" content="@gpxstudio" />
<link rel="alternate" hreflang="x-default" href="https://gpx.studio${getURLForLanguage('en', path)}" /> <link rel="alternate" hreflang="x-default" href="https://gpx.studio${getURLForLanguage('en', path)}" />`;
// the manifests are made for the website, not for the desktop app (`npm run build:desktop`)
if (process.env.BUILD_TARGET !== 'desktop') {
headTag += `
<link rel="manifest" href="/${language}.manifest.webmanifest" />`; <link rel="manifest" href="/${language}.manifest.webmanifest" />`;
}
if (page !== '404') { if (page !== '404') {
for (let lang of Object.keys(languages)) { for (let lang of Object.keys(languages)) {
+6 -1
View File
@@ -7,6 +7,9 @@ const mdsvexOptions = {
extensions: ['.mdx'], extensions: ['.mdx'],
}; };
/** 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';
/** @type {import('@sveltejs/kit').Config} */ /** @type {import('@sveltejs/kit').Config} */
const config = { const config = {
extensions: ['.svelte', ...mdsvexOptions.extensions], extensions: ['.svelte', ...mdsvexOptions.extensions],
@@ -23,7 +26,9 @@ const config = {
relative: false, relative: false,
}, },
prerender: { prerender: {
crawl: true, // the desktop app only has the pages of the app, the others are left empty (vite.config.ts)
crawl: !desktop,
handleUnseenRoutes: desktop ? 'ignore' : 'fail',
}, },
}, },
}; };
+43 -2
View File
@@ -1,9 +1,50 @@
import { sveltekit } from '@sveltejs/kit/vite'; import { sveltekit } from '@sveltejs/kit/vite';
import { enhancedImages } from '@sveltejs/enhanced-img'; import { enhancedImages } from '@sveltejs/enhanced-img';
import { defineConfig } from 'vite'; import { defineConfig, type Plugin } from 'vite';
import tailwindcss from '@tailwindcss/vite'; import tailwindcss from '@tailwindcss/vite';
import wasm from 'vite-plugin-wasm'; import wasm from 'vite-plugin-wasm';
/** 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');
}`;
}
},
};
}
export default defineConfig({ export default defineConfig({
plugins: [enhancedImages(), tailwindcss(), wasm(), sveltekit()], plugins: [
...(desktop ? [desktopBuild()] : []),
enhancedImages(),
tailwindcss(),
wasm(),
sveltekit(),
],
}); });