| 1 | /** |
| 2 | * A REAL user-owned Vite config, exactly like a normal SvelteKit v3 project: |
| 3 | * the user registers `sveltekit()` here themselves, and |
| 4 | * `@alchemy.run/frontend-frameworks/sveltekit` must load this file natively and inject its |
| 5 | * deploy-target adapter into THIS `sveltekit(...)` instance rather than |
| 6 | * constructing a second one (the user-config principle). |
| 7 | * |
| 8 | * NOTE: kit v3 (`3.0.0-next.9`) HARD-ERRORS if a `svelte.config.js`/`.ts` |
| 9 | * exists at the project root ("svelte.config.js is no longer used") — ALL |
| 10 | * configuration, including Svelte `preprocess`/`compilerOptions`, lives in |
| 11 | * this `sveltekit(...)` call. So this file carries both user-config proofs: |
| 12 | * |
| 13 | * - `alias: { $spa: "src/lib" }` — a user kit alias imported by the widgets |
| 14 | * page; the route only resolves if the user's `sveltekit()` call is the |
| 15 | * one that runs. |
| 16 | * - `preprocess: [markerPreprocessor]` — rewrites the literal |
| 17 | * `__SVELTE_CONFIG_MARKER__` (rendered by the home page) to |
| 18 | * `svelte-config-loaded`; the smoke test asserts the replaced value, which |
| 19 | * only appears if this file's svelte configuration is honored. |
| 20 | */ |
| 21 | import { sveltekit } from "@sveltejs/kit/vite"; |
| 22 | import { defineConfig } from "vite"; |
| 23 | |
| 24 | const markerPreprocessor = { |
| 25 | name: "fixture-user-preprocessor", |
| 26 | markup: ({ content }: { content: string }) => { |
| 27 | if (!content.includes("__SVELTE_CONFIG_MARKER__")) return undefined; |
| 28 | return { |
| 29 | code: content.replaceAll( |
| 30 | "__SVELTE_CONFIG_MARKER__", |
| 31 | "svelte-config-loaded", |
| 32 | ), |
| 33 | }; |
| 34 | }, |
| 35 | }; |
| 36 | |
| 37 | export default defineConfig({ |
| 38 | plugins: [ |
| 39 | sveltekit({ |
| 40 | alias: { $spa: "src/lib" }, |
| 41 | preprocess: [markerPreprocessor], |
| 42 | }), |
| 43 | ], |
| 44 | }); |