-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.config.ts
103 lines (95 loc) · 2.52 KB
/
vite.config.ts
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
93
94
95
96
97
98
99
100
101
102
103
import { sentrySvelteKit } from '@sentry/sveltekit';
import type { SentrySvelteKitPluginOptions } from '@sentry/sveltekit/types/vite/sentryVitePlugins';
import { sveltekit } from '@sveltejs/kit/vite';
import { visualizer } from 'rollup-plugin-visualizer';
import Icons from 'unplugin-icons/vite';
import type { PluginOption } from 'vite';
import { defineConfig, loadEnv } from 'vite';
import { purgeCss } from 'vite-plugin-tailwind-purgecss';
export default defineConfig(({ mode }) => {
// Load env file based on `mode` in the current working directory.
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
const env = loadEnv(mode, process.cwd());
return {
build: {
minify: 'esbuild',
},
server: {
host: 'localhost',
port: 3000,
strictPort: true,
},
preview: {
port: 3000,
},
plugins: [
...getWrappedSentrySvelteKitPlugin(mode, env),
sveltekit(),
Icons({
compiler: 'svelte',
}),
/*
* https://www.skeleton.dev/docs/purgecss
*/
purgeCss(),
visualizer({
/**
* Emitted to `./.svelte-kit/output`
* during `vite build` (not `vite dev`).
* Separate reports in `server/` and `client/` folders.
*/
emitFile: true,
filename: 'stats.html',
template: 'treemap',
gzipSize: true,
brotliSize: true,
}) as PluginOption,
],
};
});
function getWrappedSentrySvelteKitPlugin(
mode: string,
env: Record<string, string>,
): PluginOption[] {
if (mode === 'test') {
return [];
}
const plugin = sentrySvelteKit({
debug: mode !== 'production',
...setupSentrySourceMapsUpload(
env['VITE_SENTRY_ORG'],
env['VITE_SENTRY_PROJECT'],
env['VITE_SENTRY_AUTH_TOKEN'],
),
});
return [plugin];
}
function setupSentrySourceMapsUpload(
org: string | undefined,
project: string | undefined,
authToken: string | undefined,
): SentrySvelteKitPluginOptions {
if (!org || !project || !authToken) {
console.warn(
'Sentry Org, Project, and/or Auth token is invalid or unset. Source maps upload is disabled',
);
console.warn(
`Sentry - Org: ${org}, Project: ${project}, Auth Token: ${authToken}`,
);
return {
autoUploadSourceMaps: false,
sourceMapsUploadOptions: {
telemetry: false,
},
};
}
return {
autoUploadSourceMaps: true,
sourceMapsUploadOptions: {
telemetry: false,
org,
project,
authToken,
},
};
}