Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
69 lines (66 loc) · 2.23 KB
/
Copy pathvite.config.ts
File metadata and controls
69 lines (66 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import adapter from '@sveltejs/adapter-node';
import { sveltekit } from '@sveltejs/kit/vite';
import tailwindcss from '@tailwindcss/vite';
import { readFileSync } from 'node:fs';
import { defineConfig } from 'vite';
// Release version shown in the footer. Release workflows bump package.json before tagging.
const { version } = JSON.parse(readFileSync('package.json', 'utf8')) as { version: string };
// Hosts gtag.js sends GA4 hits to (#166). A `*.` wildcard needs a subdomain, so the bare
// analytics.google.com is listed on its own; with Google signals on, hits also go to
// www.google.com and stats.g.doubleclick.net.
const GA_HOSTS = [
'https://*.google-analytics.com',
'https://*.analytics.google.com',
'https://analytics.google.com',
'https://*.googletagmanager.com',
'https://www.google.com',
'https://*.g.doubleclick.net'
] as const;
export default defineConfig({
define: {
__APP_VERSION__: JSON.stringify(version)
},
plugins: [
tailwindcss(),
sveltekit({
compilerOptions: {
runes: ({ filename }) =>
filename.split(/[/\\]/).includes('node_modules') ? undefined : true
},
adapter: adapter({ out: 'build' }),
// Per-request nonces for SSR pages; the pre-paint theme script in app.html carries
// %sveltekit.nonce%. Third-party: GA4 (gtag) and map tiles (images only).
csp: {
mode: 'auto',
directives: {
'default-src': ['self'],
'script-src': ['self', 'https://www.googletagmanager.com'],
// Svelte `style:` directives use inline styles.
'style-src': ['self', 'unsafe-inline'],
// Map tiles for the interactive maps (#29): Esri imagery and OpenStreetMap.
// GA4 beacons may use image pings (Google's CSP guide for GA4 with signals).
// The country-specific ga-audiences pixel (www.google.com.au…) stays blocked.
'img-src': [
'self',
'data:',
'https://server.arcgisonline.com',
'https://tile.openstreetmap.org',
...GA_HOSTS
],
'font-src': ['self', 'data:'],
'connect-src': ['self', ...GA_HOSTS],
'object-src': ['none'],
'base-uri': ['self'],
'form-action': ['self'],
'frame-ancestors': ['none']
}
}
})
],
ssr: {
external: ['better-sqlite3']
},
optimizeDeps: {
exclude: ['better-sqlite3']
}
});