-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
88 lines (85 loc) · 2.26 KB
/
vite.config.js
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
import { execSync } from 'node:child_process';
import { readFile } from 'node:fs/promises';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import json5Plugin from 'vite-plugin-json5';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
/** @see https://vitejs.dev/config */
export default async () => {
let revision;
try {
revision = execSync('git log --format="%h" -n1', { timeout: 100, encoding: 'utf-8' }).trim();
if (execSync('git status -s', { timeout: 100, encoding: 'utf-8' }).trim()) {
// repo is dirty (has uncommitted files)
revision += '~';
}
} catch (_) {
/* ignore */
}
return defineConfig({
assetsInclude: ['/sb-preview/runtime.js'],
esbuild: {
loader: 'jsx',
},
plugins: [
react(),
json5Plugin(),
nodePolyfills({
include: ['./node_modules/**/*.js', '../../node_modules/**/*.js'],
globals: {
Buffer: true,
},
}),
],
define: {
__VERSION__: JSON.stringify(
await readFile('package.json')
.then(JSON.parse)
.then(({ version }) => version),
),
process: JSON.stringify({
env: {
NODE_ENV: process.env.NODE_ENV,
REVISION: revision,
},
arch: 'wasm',
platform: 'web',
}),
},
worker: {
format: 'es',
},
preview: {
https: true,
},
build: {
rollupOptions: {
output: {
generatedCode: 'es2015',
},
},
},
server: {
host: 'localhost',
proxy: {
'/api': {
target: process.env.TAMANU_VITE_TARGET ?? 'https://facility-1.main.internal.tamanu.io',
// specify other servers to use as backend by setting the environment variable, e.g.
// TAMANU_VITE_TARGET=http://localhost:3000
// TAMANU_VITE_TARGET=http://localhost:4000
// TAMANU_VITE_TARGET=https://central.main.internal.tamanu.io
changeOrigin: true,
},
'/socket.io': {
target: process.env.TAMANU_VITE_TARGET ?? 'https://facility-1.main.internal.tamanu.io',
ws: true,
},
},
},
test: {
clearMocks: true,
globals: true,
environment: 'jsdom',
},
});
};