-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathvite.config.ts
More file actions
92 lines (85 loc) · 2.75 KB
/
vite.config.ts
File metadata and controls
92 lines (85 loc) · 2.75 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { enhancedImages } from '@sveltejs/enhanced-img'
import { sveltekit } from '@sveltejs/kit/vite'
import { execSync } from 'child_process'
import dotenv from 'dotenv'
import fs from 'fs'
import path from 'path'
import { defineConfig } from 'vite'
import lucidePreprocess from 'vite-plugin-lucide-preprocess'
import { sentryVitePlugin } from '@sentry/vite-plugin'
import { isDev } from './src/lib/env'
import { MARKDOWN_L10NS } from './src/lib/l10n'
import { locales as compiledLocales } from './src/lib/paraglide/runtime.js'
function getSentryRelease(): string | undefined {
try {
return process.env.COMMIT_REF || execSync('git rev-parse HEAD').toString().trim()
} catch {
return undefined
}
}
function getLocaleExcludePatterns(): RegExp[] {
const md = path.resolve(MARKDOWN_L10NS)
const reposLocales = fs.existsSync(md)
? fs.readdirSync(md).filter((item) => fs.statSync(path.join(md, item)).isDirectory())
: [] // the directory may not exist when running tests
// console.debug(`📁 Locale directories found in repos: ${reposLocales.join(', ')}`)
const locales: readonly string[] = compiledLocales
const toExclude = reposLocales.filter((locale) => !locales.includes(locale))
// console.debug(`🚫 Excluding locales from build: [${toExclude.join(', ')]}`)
return toExclude.map((locale) => {
const pattern = new RegExp(`${MARKDOWN_L10NS}/${locale}/`)
// console.debug(`📋 Created exclude pattern: ${pattern}`)
return pattern
})
}
export default defineConfig(() => {
// Guarantees server can see .env (on e.g. hot restart)
dotenv.config({ override: true })
return {
define: {
'import.meta.env.SENTRY_RELEASE': JSON.stringify(getSentryRelease())
},
server: {
port: 37572,
fs: {
// Allow serving files from l10n-cage directory
allow: [MARKDOWN_L10NS]
}
},
// Improve build performance and reduce log output
build: {
// Do not output sizes for every chunk
reportCompressedSize: false,
// Increase warning limit to reduce output
chunkSizeWarningLimit: 5000,
// Improve cache usage
cssCodeSplit: true,
sourcemap: true,
// Exclude repos locale paths not in runtime.locales
rollupOptions: {
external: getLocaleExcludePatterns()
}
} as const,
plugins: [
lucidePreprocess(),
enhancedImages(),
sveltekit(),
!isDev(process.env) &&
process.env.SENTRY_AUTH_TOKEN &&
process.env.SENTRY_ORG &&
process.env.SENTRY_PROJECT
? sentryVitePlugin({
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
authToken: process.env.SENTRY_AUTH_TOKEN,
release: { name: getSentryRelease() },
sourcemaps: {
filesToDeleteAfterUpload: ['./build/**/*.map']
},
telemetry: false,
silent: true
})
: null
].filter(Boolean)
}
})