mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-16 03:40:37 +08:00
Changes which were needed after the upgrade: - Replace vite-plugin-virtual (vite 8 incompatible) with vite's built-in `define` for the buildTimeConfig injection - tsconfig: drop deprecated `baseUrl` (TS 5+ resolves `paths` relative to tsconfig) - Vitest 4: import `defineConfig` from `vitest/config` so `test` is valid in vite configs - Zod 4: rename `.errors` to `.issues`, make `ZodSchema` a type-only import, drop the removed `SafeParseReturnType` - Tighten/loosen generic casts in localStore to match stricter zod 4 inference - ESLint 9 `no-useless-assignment`: remove redundant initializers and dead reassignments; disable the rule where Svelte's reactive blocks confuse the analyser - Svelte/eslint `prefer-svelte-reactivity`: disable for legacy Svelte usages of URL / Set - Misc naming-convention and prefer-const fixes
124 lines
3.7 KiB
TypeScript
124 lines
3.7 KiB
TypeScript
import config from "config";
|
|
import path from "node:path";
|
|
import { defineConfig } from "vitest/config";
|
|
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
|
|
export default defineConfig({
|
|
define: {
|
|
buildTimeConfig: JSON.stringify(config.util.toObject()),
|
|
},
|
|
test: {
|
|
environment: "happy-dom",
|
|
include: ["tests/unit/**/*.test.ts"],
|
|
reporters: "verbose",
|
|
},
|
|
plugins: [
|
|
svelte({
|
|
// Reference: https://github.com/sveltejs/vite-plugin-svelte/issues/270#issuecomment-1033190138
|
|
dynamicCompileOptions({ filename }) {
|
|
if (
|
|
path.basename(filename) === "Clipboard.svelte" ||
|
|
path.basename(filename) === "ExternalLink.svelte" ||
|
|
path.basename(filename) === "Icon.svelte"
|
|
) {
|
|
return { customElement: true };
|
|
}
|
|
},
|
|
compilerOptions: { dev: process.env.NODE_ENV !== "production" },
|
|
}),
|
|
{
|
|
name: "inject-config-loader",
|
|
transformIndexHtml() {
|
|
if (process.env.VITE_RUNTIME_CONFIG === "true") {
|
|
return [
|
|
{
|
|
tag: "script",
|
|
attrs: {
|
|
type: "text/javascript",
|
|
},
|
|
children: `
|
|
try {
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.open("GET", "/config.json", false);
|
|
xhr.send(null);
|
|
window.__CONFIG__ = JSON.parse(xhr.responseText);
|
|
} catch {
|
|
console.warn("Couldn't load config.json from the server, using built-in fallback config.");
|
|
}
|
|
`,
|
|
injectTo: "head-prepend",
|
|
},
|
|
];
|
|
}
|
|
},
|
|
},
|
|
],
|
|
optimizeDeps: {
|
|
include: [
|
|
"@wooorm/starry-night",
|
|
"@wooorm/starry-night/etc",
|
|
"@wooorm/starry-night/go.mod",
|
|
"@wooorm/starry-night/go.sum",
|
|
"@wooorm/starry-night/source.batchfile",
|
|
"@wooorm/starry-night/source.dockerfile",
|
|
"@wooorm/starry-night/source.dotenv",
|
|
"@wooorm/starry-night/source.editorconfig",
|
|
"@wooorm/starry-night/source.erlang",
|
|
"@wooorm/starry-night/source.git-revlist",
|
|
"@wooorm/starry-night/source.gitattributes",
|
|
"@wooorm/starry-night/source.gitconfig",
|
|
"@wooorm/starry-night/source.gitignore",
|
|
"@wooorm/starry-night/source.groovy.gradle",
|
|
"@wooorm/starry-night/source.haproxy-config",
|
|
"@wooorm/starry-night/source.ini.npmrc",
|
|
"@wooorm/starry-night/source.json",
|
|
"@wooorm/starry-night/source.nix",
|
|
"@wooorm/starry-night/source.sass",
|
|
"@wooorm/starry-night/source.solidity",
|
|
"@wooorm/starry-night/source.svelte",
|
|
"@wooorm/starry-night/source.toml",
|
|
"@wooorm/starry-night/source.tsx",
|
|
"@wooorm/starry-night/source.zig",
|
|
"@wooorm/starry-night/text.html.asciidoc",
|
|
"@wooorm/starry-night/text.html.django",
|
|
"@wooorm/starry-night/text.html.vue",
|
|
"@wooorm/starry-night/text.robots-txt",
|
|
"@wooorm/starry-night/text.zone_file",
|
|
],
|
|
},
|
|
server: {
|
|
host: "localhost",
|
|
port: 3000,
|
|
watch: {
|
|
// reference: https://stackoverflow.com/a/75238360
|
|
useFsEvents: false,
|
|
},
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
"@app": path.resolve("./src"),
|
|
"@public": path.resolve("./public"),
|
|
"@http-client": path.resolve("./http-client"),
|
|
"@tests": path.resolve("./tests"),
|
|
},
|
|
},
|
|
build: {
|
|
outDir: "build",
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks: id => {
|
|
if (id.includes("lodash")) {
|
|
return "lodash";
|
|
} else if (id.includes("katex")) {
|
|
return "katex";
|
|
} else if (id.includes("node_modules")) {
|
|
return "vendor";
|
|
} else if (id.includes("components")) {
|
|
return "components";
|
|
}
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|