flotilla/svelte.config.js

48 lines
1.5 KiB
JavaScript
Raw Normal View History

2024-08-21 20:20:59 +00:00
import adapter from "@sveltejs/adapter-static"
2024-08-05 22:28:46 +00:00
import {vitePreprocess} from "@sveltejs/vite-plugin-svelte"
import {createHash} from "node:crypto"
import {readFileSync} from "node:fs"
// Sveltekit hashes the scripts it injects itself, but not the ones app.html carries, so those
// have to be named in script-src by hand. Hashing them here rather than pasting a literal is
// what stops an edit to app.html silently violating the policy.
const appHtmlScripts = [
...readFileSync(new URL("./src/app.html", import.meta.url), "utf8").matchAll(
/<script(?![^>]*\bsrc=)[^>]*>([\s\S]*?)<\/script>/g,
),
].map(([, script]) => "sha256-" + createHash("sha256").update(script).digest("base64"))
2024-08-01 23:49:32 +00:00
/** @type {import('@sveltejs/kit').Config} */
2024-08-21 20:20:59 +00:00
export default {
2024-08-05 22:28:46 +00:00
preprocess: vitePreprocess(),
kit: {
serviceWorker: {
register: process.env.FLOTILLA_DESKTOP !== "1",
},
2024-08-21 20:20:59 +00:00
adapter: adapter({
2024-08-26 21:43:43 +00:00
fallback: "index.html",
2024-08-21 20:20:59 +00:00
}),
2024-08-05 22:28:46 +00:00
alias: {
2024-08-06 22:46:37 +00:00
"@src": "src",
"@app": "src/app",
"@lib": "src/lib",
"@assets": "src/assets",
2024-08-05 22:25:04 +00:00
},
2024-10-22 23:23:54 +00:00
csp: {
directives: {
"script-src": ["self", "wasm-unsafe-eval", "https://plausible.coracle.social", ...appHtmlScripts],
2024-10-23 16:45:06 +00:00
"worker-src": ["self", "blob:"],
"style-src": ["self", "unsafe-inline"],
2024-10-25 21:15:35 +00:00
"frame-src": ["none"],
2024-10-23 16:45:06 +00:00
"child-src": ["none"],
"form-action": ["none"],
2024-10-22 23:23:54 +00:00
},
},
2024-08-05 22:28:46 +00:00
},
2025-07-15 22:49:26 +00:00
compilerOptions: {
warningFilter: (warning) => {
2026-01-23 18:25:06 +00:00
return !['a11y_media_has_caption', 'state_referenced_locally'].includes(warning.code)
2025-07-15 22:49:26 +00:00
},
}
2024-08-05 22:28:46 +00:00
}