-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvite.examples.config.ts
More file actions
144 lines (133 loc) · 3.52 KB
/
vite.examples.config.ts
File metadata and controls
144 lines (133 loc) · 3.52 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
139
140
141
142
143
144
/*
* Copyright (c) 2023-2025 Datalayer, Inc.
* Distributed under the terms of the Modified BSD License.
*/
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import { treatAsCommonjs } from 'vite-plugin-treat-umd-as-commonjs';
import path from 'path';
export default defineConfig(({ mode }) => {
// Load env file based on `mode` in the current working directory.
const env = loadEnv(mode, process.cwd(), '');
return {
root: process.cwd(),
publicDir: false,
server: {
port: 3000,
open: true,
fs: {
strict: false,
},
proxy: {
'/api': {
target: 'https://prod1.datalayer.run',
changeOrigin: true,
secure: true,
configure: (proxy, options) => {
proxy.on('proxyReq', (proxyReq, req, res) => {
console.log(
'Proxying:',
req.method,
req.url,
'->',
options.target + (req.url || ''),
);
});
},
},
},
// Handle SPA routing - serve index.html for all routes
middlewareMode: false,
},
appType: 'spa',
plugins: [
react(),
treatAsCommonjs(),
{
name: 'html-transform',
transformIndexHtml(html) {
// Replace environment variables in HTML
return html
.replaceAll(
/%VITE_DATALAYER_API_KEY%/g,
env.VITE_DATALAYER_API_KEY || '',
)
.replaceAll(
/%VITE_DATALAYER_RUN_URL%/g,
env.VITE_DATALAYER_RUN_URL || 'https://prod1.datalayer.run',
)
.replaceAll(
/%VITE_DATALAYER_RUN_URL_WS%/g,
(
env.VITE_DATALAYER_RUN_URL || 'https://prod1.datalayer.run'
).replace('http', 'ws'),
);
},
},
{
name: 'raw-css-as-string',
enforce: 'pre',
async resolveId(source, importer) {
if (source.endsWith('.raw.css') && !source.includes('?raw')) {
// rewrite import to append ?raw query
const resolved = await this.resolve(source + '?raw', importer, {
skipSelf: true,
});
if (resolved) return resolved.id;
return null;
}
return null;
},
},
{
name: 'fix-text-query',
enforce: 'pre',
async resolveId(source, importer) {
if (source.includes('?text')) {
const fixed = source.replace('?text', '?raw');
const resolved = await this.resolve(fixed, importer, {
skipSelf: true,
});
if (resolved) {
return resolved.id;
}
return fixed;
}
return null;
},
},
],
define: {
global: 'globalThis',
__webpack_public_path__: '""',
},
assetsInclude: ['**/*.whl', '**/*.raw.css'],
resolve: {
alias: [
{
find: '@',
replacement: path.resolve(__dirname, './src'),
},
{
find: /^~(.*)$/,
replacement: '$1',
},
],
},
optimizeDeps: {
include: ['crypto-browserify', 'buffer'],
exclude: ['keytar'],
esbuildOptions: {
loader: {
'.whl': 'text',
},
},
},
build: {
rollupOptions: {
external: ['keytar'],
input: path.resolve(__dirname, 'index.html'),
},
},
};
});