Repository navigation
Expand file tree
/
Copy pathvite.config.mjs
More file actions
79 lines (75 loc) · 2.24 KB
/
Copy pathvite.config.mjs
File metadata and controls
79 lines (75 loc) · 2.24 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
// Vite is the only frontend development and production pipeline.
// Tauri serves tauri-ui/dist directly and starts this dev server on port 1430.
import { defineConfig } from 'vite';
import { resolve, dirname } from 'node:path';
import { createRequire } from 'node:module';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const tauriUiDir = resolve(__dirname, 'tauri-ui');
const require = createRequire(import.meta.url);
// The desktop UI calls the proxy management API through relative /v1/local/*
// URLs. During development the page runs on the Vite origin, so the calls only
// work when the dev server forwards them to the plain-HTTP management port and
// injects the management token. Packaged builds use the Tauri native bridge
// instead and never take this path.
function devManagementProxy() {
const { createDevManagementProxy } = require('./lib/dev/management-proxy.js');
const middleware = createDevManagementProxy({
repoRoot: __dirname,
devPort: 1430,
logger: {
debug() {},
warn(message, detail) {
console.warn(`[dev-management-proxy] ${message}${detail ? ` ${detail}` : ''}`);
},
},
});
return {
name: 'hpm-dev-management-proxy',
configureServer(server) {
server.middlewares.use((req, res, next) => {
middleware(req, res, next).catch((error) => {
if (res.headersSent) {
res.end();
return;
}
res.statusCode = 502;
res.setHeader('Content-Type', 'application/json; charset=utf-8');
res.end(
JSON.stringify({
error: 'Dev management proxy failed: ' + String(error && error.message),
})
);
});
});
},
};
}
export default defineConfig({
root: tauriUiDir,
base: './',
publicDir: false,
clearScreen: false,
plugins: [devManagementProxy()],
server: {
port: 1430,
strictPort: true,
host: '127.0.0.1',
},
build: {
outDir: 'dist',
emptyOutDir: true,
target: 'es2022',
sourcemap: false,
minify: 'esbuild',
cssCodeSplit: true,
},
esbuild: {
target: 'es2022',
legalComments: 'none',
},
optimizeDeps: {
include: [],
},
});