-
Notifications
You must be signed in to change notification settings - Fork 44
/
vite.config.ts
110 lines (107 loc) · 3.75 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
104
105
106
107
108
109
110
/// <reference types="vitest" />
/// <reference types="vite-plugin-svgr/client" />
import { defineConfig, ConfigEnv, UserConfigExport } from 'vite';
import react from '@vitejs/plugin-react';
// import eslint from 'vite-plugin-eslint';
import viteTsconfigPaths from 'vite-tsconfig-paths';
import checker from 'vite-plugin-checker';
import svgrPlugin from 'vite-plugin-svgr';
import fs from 'fs';
import nodePolyfills from 'rollup-plugin-polyfill-node';
// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfigExport => {
if (mode === 'test' && command === 'serve') {
return defineConfig({
// dev specific config
plugins: [react(), viteTsconfigPaths(), svgrPlugin()],
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis',
},
},
},
resolve: { alias: { util: 'util/' } },
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/setupTests.ts',
coverage: {
reporter: ['lcov', 'text', 'html'],
// choosing istanbul for now because of this https://github.com/vitest-dev/vitest/issues/1252
provider: 'istanbul', // or 'c8',
include: ['src/**/**'],
exclude: ['node_modules/', '**/*.test.tsx', './src/assets/**'],
},
css: true,
},
});
}
if (command === 'serve') {
return defineConfig({
// dev specific config
plugins: [react(), viteTsconfigPaths(), svgrPlugin(), checker({ typescript: true })],
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis',
},
},
},
server: {
open: true,
port: 3000,
https: {
key: fs.readFileSync('../glific/priv/cert/glific.test+1-key.pem'),
cert: fs.readFileSync('../glific/priv/cert/glific.test+1.pem'),
},
headers: {
'X-Content-Type-Options': 'nosniff',
'X-XSS-Protection': '1; mode=block',
'X-Frame-Options': 'deny',
'Content-Security-Policy':
"default-src * data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:; script-src-elem 'self' 'unsafe-inline' https://www.google.com https://www.gstatic.com https://js.stripe.com ; frame-src 'self' https://js.stripe.com/ https://www.google.com https://www.gstatic.com data:; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' data: https://fonts.gstatic.com; connect-src *;",
'Strict-Transport-Security': 'max-age=63072000; includeSubdomains; preload',
},
},
resolve: { alias: { util: 'util/', stream: 'stream-browserify' } }, // stream polyfill is needed by logflare
});
}
// command === 'build'
return defineConfig({
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis',
},
},
},
// build specific config
plugins: [react(), viteTsconfigPaths(), svgrPlugin()],
build: {
// this is needed because of this https://github.com/vitejs/vite/issues/2139#issuecomment-1405624744
commonjsOptions: {
defaultIsModuleExports(id) {
try {
const module = require(id);
if (module?.default) {
return false;
}
return 'auto';
} catch (error) {
return 'auto';
}
},
transformMixedEsModules: true,
},
outDir: 'build',
rollupOptions: {
plugins: [nodePolyfills('buffer', 'process')],
},
},
resolve: { alias: { util: 'util/', stream: 'stream-browserify' } },
});
};