-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathvite.config.mts
96 lines (91 loc) · 2.99 KB
/
vite.config.mts
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
import basicSsl from '@vitejs/plugin-basic-ssl';
import react from '@vitejs/plugin-react';
import fs from 'node:fs';
import path from 'node:path';
import * as process from 'process';
import { visualizer } from 'rollup-plugin-visualizer';
import tsconfigPaths from 'vite-tsconfig-paths';
import { defineConfig } from 'vitest/config';
import routePaths from './src/routes/routePaths';
import { htmlPrerender } from './vite-plugin-html-prerender/src/index';
import { sentryVitePlugin } from '@sentry/vite-plugin';
// @ts-expect-error missing types for the lib
import ReactCompilerBabelPlugin from 'babel-plugin-react-compiler';
const certPath = './config/crt/server.pem';
const keyPath = './config/crt/server.key';
const customCert = fs.existsSync(certPath);
if (!customCert) {
console.log('No custom cert found, Service Worker might not work. Check README.md how to fix it');
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
sentryVitePlugin({
applicationKey: 'allkaraoke-party-sentry-key',
}),
ReactCompilerBabelPlugin,
react({
babel: {
plugins: [
'@emotion',
// https://mui.com/material-ui/guides/minimizing-bundle-size/
[
'transform-imports',
{
'@mui/icons-material': {
transform: '@mui/icons-material/${member}',
preventFullImport: true,
},
'@mui/material': {
transform: '@mui/material/${member}',
preventFullImport: true,
},
'lodash-es': {
transform: 'lodash-es/${member}',
preventFullImport: true,
},
},
],
],
},
jsxImportSource: process.env.NODE_ENV === 'development' ? '@welldone-software/why-did-you-render' : undefined,
}),
tsconfigPaths(),
visualizer(),
!customCert && basicSsl(),
process.env.VITE_APP_PRERENDER
? htmlPrerender({
staticDir: path.join(__dirname, 'build'),
routes: Object.values(routePaths).map((route) => `/${route}`),
minify: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
decodeEntities: true,
keepClosingSlash: true,
sortAttributes: true,
},
})
: null,
],
base: '/',
build: {
outDir: 'build',
sourcemap: !process.env.FAST_BUILD,
reportCompressedSize: !process.env.FAST_BUILD,
},
server: {
port: 3000,
open: 'https://localhost:3000',
https: {
// Generated via https://letsencrypt.org/docs/certificates-for-localhost/#making-and-trusting-your-own-certificates
key: fs.readFileSync(customCert ? keyPath : './config/crt/dummy.key'),
cert: fs.readFileSync(customCert ? certPath : './config/crt/dummy.pem'),
},
},
test: {
include: ['**/*.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
globals: true,
environment: 'happy-dom',
setupFiles: 'src/setupTests.ts',
},
});