-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
92 lines (81 loc) · 2.07 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
import path from 'node:path';
import { preact } from '@preact/preset-vite';
import typescript from '@rollup/plugin-typescript';
import { sentryVitePlugin } from '@sentry/vite-plugin';
import { defineConfig, loadEnv, UserConfig } from 'vite';
import svgr from 'vite-plugin-svgr';
// Vite is used for JavaScript bundling and development server
// CSS is built separately by PostCSS
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const config: UserConfig = {
define: {
'process.env': env,
},
server: {
port: 3020,
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
plugins: [svgr(), preact()],
test: {
testTimeout: env.PWDEBUG ? 0 : 5000,
fileParallelism: false,
environmentMatchGlobs: [['tests/unit/**', 'happy-dom']],
},
};
if (!env.VITE_TEST) {
config.build = {
sourcemap: true,
manifest: true,
minify: true,
reportCompressedSize: true,
lib: {
entry: path.resolve(__dirname, 'src/index.tsx'),
fileName: 'index',
formats: ['es', 'cjs'],
},
rollupOptions: {
plugins: [
typescript({
sourceMap: false,
declaration: true,
outDir: 'dist',
include: [
'node_modules/vite/client.d.ts',
'src/**/*.ts',
'src/**/*.tsx',
],
}),
] as any[],
},
};
}
if (mode === 'production' && env.VITE_SENTRY_DSN) {
config.plugins.push(
sentryVitePlugin({
authToken: env.SENTRY_AUTH_TOKEN,
org: env.SENTRY_ORG,
project: env.SENTRY_PROJECT,
}),
);
}
if (mode === 'development') {
config.plugins.push({
name: 'reload-on-public-file-change',
handleHotUpdate({ file, server }) {
if (file.includes('public')) {
server.ws.send({
type: 'full-reload',
path: '*',
});
}
},
});
}
return config;
});