-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathvite.config.ts
122 lines (114 loc) · 3.59 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
111
112
113
114
115
116
117
118
119
120
121
122
/* eslint-disable import/no-extraneous-dependencies */
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react-swc';
import path from 'path';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const packagesDir = path.resolve(__dirname, '..');
let port = Number.parseInt(env.PORT, 10);
if (Number.isNaN(port) || port <= 0) {
port = 4010;
}
const baseURL = new URL(env.BASE_URL, `http://localhost:${port}/`);
// These are paths which should be proxied to the core server
// https://vitejs.dev/config/server-options.html#server-proxy
const proxy = {
// proxy the websocket requests, allows tunneling to work with a single port
'^/arrow\\.*': {
target: env.VITE_PROXY_URL,
changeOrigin: true,
ws: true,
},
'^/io\\.deephaven\\..*': {
target: env.VITE_PROXY_URL,
changeOrigin: true,
ws: true,
},
};
// Some paths need to proxy to the engine server
// Vite does not have a "any unknown fallback to proxy" like CRA
// It is possible to add one with a custom middleware though if this list grows
if (env.VITE_PROXY_URL) {
[env.VITE_CORE_API_URL, env.VITE_MODULE_PLUGINS_URL].forEach(p => {
const route = new URL(p, baseURL).pathname;
proxy[route] = {
target: env.VITE_PROXY_URL,
changeOrigin: true,
};
});
}
// Proxy to local dev server for js-plugins
if (env.VITE_JS_PLUGINS_DEV_PORT && env.VITE_MODULE_PLUGINS_URL) {
const route = new URL(env.VITE_MODULE_PLUGINS_URL, baseURL).pathname;
proxy[route] = {
target: `http://localhost:${env.VITE_JS_PLUGINS_DEV_PORT}`,
changeOrigin: true,
rewrite: (pathOrig: string) => pathOrig.replace(/^\/js-plugins/, ''),
};
}
return {
base: './', // Vite defaults to absolute URLs, but embed-widget is an embedded deployment so all assets are relative paths
envPrefix: ['VITE_', 'npm_'], // Needed to use $npm_package_version
server: {
port,
proxy,
},
preview: {
port,
proxy,
},
resolve: {
dedupe: ['react', 'react-redux', 'redux'],
alias:
mode === 'development'
? [
{
find: /^@deephaven\/(.*)\/scss\/(.*)/,
replacement: `${packagesDir}/$1/scss/$2`,
},
{
find: /^@deephaven\/(?!icons|jsapi-types)(.*)/, // Icons package can not import from src
replacement: `${packagesDir}/$1/src`,
},
]
: [],
},
build: {
outDir: env.VITE_BUILD_PATH,
emptyOutDir: true,
sourcemap: true,
rollupOptions: {
output: {
manualChunks: id => {
/**
* Without this, our chunk order may cause a circular reference
* by putting the helpers in the vendor or plotly chunk
* This causes failures with loading the compiled version
*
* See https://github.com/rollup/plugins/issues/591
*/
if (id === '\0commonjsHelpers.js') {
return 'helpers';
}
if (id.includes('node_modules')) {
if (id.includes('plotly.js')) {
return 'plotly';
}
return 'vendor';
}
},
},
},
},
optimizeDeps: {
esbuildOptions: {
// Some packages need this to start properly if they reference global
define: {
global: 'globalThis',
},
},
},
plugins: [react()],
};
});