-
Notifications
You must be signed in to change notification settings - Fork 903
/
vite.config.cts
126 lines (121 loc) · 3.66 KB
/
vite.config.cts
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/// <reference types="vitest" />
import eslintPlugin from '@nabla/vite-plugin-eslint';
import { sentryVitePlugin, SentryVitePluginOptions } from '@sentry/vite-plugin';
import react from '@vitejs/plugin-react';
import jotaiDebugLabel from 'jotai/babel/plugin-debug-label';
import jotaiReactRefresh from 'jotai/babel/plugin-react-refresh';
import { defineConfig } from 'vite';
// import { VitePWA } from 'vite-plugin-pwa';
import replace from '@rollup/plugin-replace';
import tsconfigPaths from 'vite-tsconfig-paths';
const manualChunkMap = {
'@sentry': 'sentry',
'@radix-ui': 'radix',
'country-flag-icons': 'flags',
recharts: 'recharts',
'world.json': 'world',
'usa_states.json': 'config',
'zones.json': 'config',
'exchanges.json': 'config',
'excluded_aggregated_exchanges.json': 'config',
};
const sentryPluginOptions: SentryVitePluginOptions = {
org: 'electricitymaps',
project: 'app-web',
// Auth tokens can be obtained from https://sentry.io/settings/account/api/auth-tokens/
// and needs the `project:releases` and `org:read` scopes
authToken: process.env.SENTRY_AUTH_TOKEN,
sourcemaps: {
// Specify the directory containing build artifacts
assets: ['./dist'],
},
release: {
// Optionally uncomment the line below to override automatic release name detection
name: process.env.npm_package_version,
},
};
export default defineConfig(({ mode }) => ({
define: {
APP_VERSION: JSON.stringify(process.env.npm_package_version),
},
server: { host: '127.0.0.1' },
build: {
sourcemap: true,
rollupOptions: {
output: {
manualChunks(id) {
for (const [searchString, value] of Object.entries(manualChunkMap)) {
if (id.includes(searchString)) {
return value;
}
}
},
},
},
},
treeshake: 'smallest',
test: {
css: false,
include: ['{src,geo}/**/*.test.{ts,tsx}', 'scripts/*.test.{ts,tsx}'],
globals: true,
globalSetup: 'testSetup.ts',
environment: 'jsdom',
setupFiles: 'src/testing/setupTests.ts',
clearMocks: true,
coverage: {
provider: 'istanbul',
enabled: false,
100: true,
reporter: ['text', 'lcov'],
reportsDirectory: 'coverage',
},
},
plugins: [
replace({
__SENTRY_TRACING__: false,
}),
tsconfigPaths(),
react({
babel: {
plugins: [jotaiDebugLabel, jotaiReactRefresh],
},
}),
...(mode !== 'test'
? [
eslintPlugin(),
// Temporarily disabled to ensure we can more easily rollback
// VitePWA({
// registerType: 'autoUpdate',
// workbox: {
// maximumFileSizeToCacheInBytes: 3_500_000,
// },
// includeAssets: [
// 'icons/*.{svg,png}',
// 'robots.txt',
// // Consider if we should also add subdirectories below
// 'images/*.{svg,png}',
// 'fonts/*.woff2',
// ],
// manifest: {
// theme_color: '#000000',
// icons: [
// {
// src: '/icons/android-chrome-192x192.png',
// sizes: '192x192',
// type: 'image/png',
// purpose: 'any maskable',
// },
// {
// src: '/icons/android-chrome-512x512.png',
// sizes: '512x512',
// type: 'image/png',
// },
// ],
// },
// }),
// Used to upload sourcemaps to Sentry
process.env.SENTRY_AUTH_TOKEN && sentryVitePlugin(sentryPluginOptions),
]
: []),
],
}));