forked from deephaven/web-client-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
138 lines (129 loc) · 3.89 KB
/
Copy pathvite.config.ts
File metadata and controls
138 lines (129 loc) · 3.89 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// This is a dev dependency for building, so importing dev deps is fine
/* eslint-disable import/no-extraneous-dependencies */
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import dns from 'dns';
// Open on localhost instead of 127.0.0.1 for Node < 17
// https://github.com/vitejs/vite/issues/9195
dns.setDefaultResultOrder('verbatim');
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
// https://github.com/vitejs/vite/issues/3105#issuecomment-939703781
const htmlPlugin = () => ({
name: 'html-transform',
transformIndexHtml: {
enforce: 'pre' as const,
transform(html: string) {
return html.replace(/#(.*?)#/g, (_, p1) => env[p1]);
},
},
});
const packagesDir = path.resolve(__dirname, '..');
let port = Number.parseInt(env.PORT, 10);
if (Number.isNaN(port) || port <= 0) {
port = 4000;
}
// These are paths which should be proxied to the core server
// https://vitejs.dev/config/server-options.html#server-proxy
const proxy = {
// Proxy styleguide here instead of as a route in our app router
// That way, it is not included in the production build
'/styleguide': {
target: `http://localhost:${port}/src/styleguide/index.html`,
rewrite: () => '',
},
};
// 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_NOTEBOOKS_URL,
env.VITE_LAYOUTS_URL,
env.VITE_MODULE_PLUGINS_URL,
].forEach(p => {
proxy[p] = {
target: env.VITE_PROXY_URL,
changeOrigin: true,
};
});
}
return {
// Vite does not read this env variable, it sets it based on the config
// For easy changes using our .env files, read it here and vite will just set it to the existing value
base: env.BASE_URL,
envPrefix: ['VITE_', 'npm_'], // Needed to use $npm_package_version
server: {
port,
open: true,
proxy,
},
preview: {
port,
open: true,
proxy,
},
resolve: {
dedupe: ['react', 'react-redux', 'redux'],
alias: [
{
find: /^@deephaven\/components\/scss\/(.*)/,
replacement: `${packagesDir}/components/scss/$1`,
},
{
find: /^@deephaven\/icons$/,
replacement: `${packagesDir}/icons/dist/index.es.js`,
},
{
find: /^@deephaven\/(.*)/,
replacement: `${packagesDir}/$1/src`,
},
],
},
build: {
outDir: path.resolve(__dirname, 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('monaco-editor')) {
return 'monaco';
}
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',
},
},
},
css: {
devSourcemap: true,
},
plugins: [htmlPlugin(), react()],
};
});