Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
136 lines (132 loc) · 4.44 KB
/
Copy pathvite.config.ts
File metadata and controls
136 lines (132 loc) · 4.44 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
/// <reference types="vitest/config" />
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import { fileURLToPath } from 'url';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import { resolveDevApiPort } from '../../scripts/dev-api-port.mjs';
const root = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.resolve(root, '../..');
const isTauri = Boolean(process.env.TAURI_ENV_PLATFORM);
function pick(env: Record<string, string>, ...keys: string[]) {
for (const key of keys) {
const value = String(env[key] ?? '').trim();
if (value) return value;
}
return '';
}
export default defineConfig(({ mode }) => {
const env = { ...loadEnv(mode, repoRoot, ''), ...loadEnv(mode, root, '') };
const devApiPort = resolveDevApiPort(env);
const apiBaseUrl = pick(env, 'VITE_API_BASE_URL').replace(/\/$/, '');
const apiProxyTarget =
apiBaseUrl && /^https?:\/\//i.test(apiBaseUrl) && !/localhost|127\.0\.0\.1/i.test(apiBaseUrl)
? apiBaseUrl
: `http://127.0.0.1:${devApiPort}`;
return {
clearScreen: false,
plugins: [
react(),
createSvgIconsPlugin({
iconDirs: [path.join(root, 'src/assets/svg')],
symbolId: 'icon-[dir]-[name]',
inject: 'body-last',
customDomId: '__svg__icons__dom__',
svgoOptions: {
plugins: [{ name: 'preset-default', params: { overrides: { removeViewBox: false } } }],
},
}),
],
define: {
__GOOGLE_CLIENT_ID__: JSON.stringify(pick(env, 'GOOGLE_CLIENT_ID', 'VITE_GOOGLE_CLIENT_ID')),
__DOCS_URL__: JSON.stringify(
pick(env, 'VITE_DOCS_URL') ||
(mode === 'development' ? 'http://localhost:5175' : 'https://recombyn.github.io/recombyn')
),
__DESKTOP_MODE__: JSON.stringify(pick(env, 'VITE_DESKTOP_MODE', 'RECOMBYN_DESKTOP_MODE').toLowerCase()),
__API_BASE_URL__: JSON.stringify(apiBaseUrl),
},
envPrefix: ['VITE_', 'TAURI_ENV_*'],
resolve: {
alias: [
{ find: '@', replacement: path.join(root, 'src') },
{ find: '@canvas-plugins', replacement: path.join(repoRoot, 'plugins/canvas') },
// Prefix form so `@rcb-vector/types` → `…/src/types.ts` (Vite 8 string
// aliases without `/` are exact-match only in some resolve paths).
{
find: /^@rcb-vector\/(.*)/,
replacement: path.join(repoRoot, 'vendor/vector-editor-ref/packages/editor/src/$1'),
},
{
find: '@rcb-vector',
replacement: path.join(repoRoot, 'vendor/vector-editor-ref/packages/editor/src'),
},
],
extensionAlias: {
'.js': ['.ts', '.tsx', '.js', '.jsx'],
'.jsx': ['.tsx', '.jsx'],
},
},
optimizeDeps: {
include: [
'fontkit',
'@orpc/client',
'@orpc/contract',
'@orpc/openapi-client',
'@orpc/openapi-client/fetch',
'@orpc/tanstack-query',
'@tanstack/react-query',
'nuqs',
'nuqs/adapters/react-router/v6',
],
exclude: [
'@ffmpeg/ffmpeg',
'@ffmpeg/util',
'@ffmpeg/core',
'@orpc/server',
'@recombyn/contracts',
],
},
assetsInclude: ['**/*.wasm'],
server: {
host: true,
port: 3000,
strictPort: true,
open: !isTauri,
fs: { allow: [root, repoRoot, path.join(repoRoot, 'vendor/vector-editor-ref')] },
watch: { ignored: ['**/src-tauri/**'] },
proxy: {
'/api': {
target: apiProxyTarget,
changeOrigin: true,
secure: /^https:/i.test(apiProxyTarget),
timeout: 0,
proxyTimeout: 0,
},
},
},
build: {
outDir: 'dist',
sourcemap: isTauri ? Boolean(process.env.TAURI_ENV_DEBUG) : true,
...(isTauri && {
target: process.env.TAURI_ENV_PLATFORM === 'windows' ? 'chrome105' : 'safari13',
minify: process.env.TAURI_ENV_DEBUG ? false : 'esbuild',
}),
},
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./src/setupTests.ts'],
include: ['src/**/*.{test,spec}.{ts,tsx}'],
// Bench / stress suites are opt-in via `npm run test:stress` — keep them
// out of default CI so a loaded self-hosted runner does not flake gate.
exclude: [
'src/private/**',
'src/**/*.bench.test.ts',
'src/**/*stress*.test.ts',
'src/**/*Stress*.test.ts',
],
css: false,
},
};
});