Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
141 lines (137 loc) · 4 KB
/
Copy pathvite.config.ts
File metadata and controls
141 lines (137 loc) · 4 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { reactRouter } from '@react-router/dev/vite';
import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
/// <reference types="vitest" />
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';
import svgr from 'vite-plugin-svgr';
import ViteTsConfigPathsPlugin from 'vite-tsconfig-paths';
import type { ViteUserConfig } from 'vitest/config';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const vitestConfig: ViteUserConfig = {
test: {
environment: 'jsdom',
globals: true,
setupFiles: './src/test/setup.ts',
teardownTimeout: 20000,
testTimeout: 20000,
coverage: {
provider: 'v8',
reporter: ['text'],
},
include: ['./src/**/*.test.?(c|m)[jt]s?(x)'],
logHeapUsage: true,
sequence: {
hooks: 'list',
},
},
};
// https://vitejs.dev/config/
export default defineConfig({
define: {
global: 'globalThis',
},
build: {
target: ['es2020'],
sourcemap: process.env.NODE_ENV !== 'production', // to enable local server-side debugging
commonjsOptions: {
transformMixedEsModules: true,
},
rollupOptions: {
output: {
manualChunks(id) {
// Split leaflet and related packages into their own chunk
if (
id.includes('node_modules/leaflet') ||
id.includes('node_modules/react-leaflet') ||
id.includes('node_modules/@react-leaflet')
) {
return 'leaflet';
}
},
},
},
},
plugins: [
!process.env.VITEST ? reactRouter() : react(),
tailwindcss(),
// TODO - confirm if required (given manual resolutions below)
ViteTsConfigPathsPlugin({
root: './',
}),
// support import of svg files
svgr(),
VitePWA({
registerType: 'autoUpdate',
includeAssets: ['favicon.ico', 'robots.txt'],
injectRegister: null,
outDir: 'build/client',
base: '/',
manifest: false,
workbox: {
globPatterns: ['**/*.{js,css,ico,png,svg,woff,woff2}'],
navigateFallback: null, // Disable for SSR - let server handle navigation
runtimeCaching: [
{
urlPattern: ({ request }) => request.mode === 'navigate',
handler: 'NetworkFirst',
options: {
cacheName: 'pages-cache',
networkTimeoutSeconds: 3,
expiration: {
maxEntries: 50,
maxAgeSeconds: 60 * 60 * 24, // 24 hours
},
},
},
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365, // 1 year
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
{
urlPattern: /^https:\/\/storage\.googleapis\.com\/.*/i,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'gcs-cache',
expiration: {
maxEntries: 50,
maxAgeSeconds: 60 * 60 * 24 * 30, // 30 days
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
},
devOptions: {
enabled: false,
},
}),
],
// open browser with server (note, will open at 127.0.1 not localhost on node <17)
// https://vitejs.dev/config/server-options.html#server-options
ssr: {
noExternal: ['remix-utils', '@mui/base', '@mui/utils', '@mui/types'],
},
resolve: {
alias: {
'oa-shared': resolve(__dirname, './shared/index.ts'),
'oa-components': resolve(__dirname, './packages/components/src/index.ts'),
},
},
test: vitestConfig.test,
});