-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvite.config.ts
More file actions
89 lines (82 loc) · 2.54 KB
/
Copy pathvite.config.ts
File metadata and controls
89 lines (82 loc) · 2.54 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
import { type ChildProcess, spawn } from 'node:child_process'
import path from 'node:path'
import tailwindcss from '@tailwindcss/vite'
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import pkg from './package.json' with { type: 'json' }
const RC_ADDR = '127.0.0.1'
const RC_PORT = '5572'
const RC_USER = 'dev'
const RC_PASS = 'dev'
const RC_URL = `http://${RC_ADDR}:${RC_PORT}`
function devRclone(): import('vite').Plugin {
let rclone: ChildProcess | null = null
return {
name: 'dev-rclone',
apply: 'serve',
configureServer(server) {
const bin = process.env.RCLONE_BIN ?? 'rclone'
const origin = `http://localhost:${server.config.server.port ?? 5173}`
rclone = spawn(
bin,
[
'rcd',
'--rc-addr',
`${RC_ADDR}:${RC_PORT}`,
'--rc-user',
RC_USER,
'--rc-pass',
RC_PASS,
'--rc-allow-origin',
origin,
],
{ stdio: 'ignore' }
)
rclone.on('error', (err) => {
server.config.logger.error(`[rclone] ${err.message}`)
})
server.httpServer?.on('close', () => {
rclone?.kill()
})
const original = server.printUrls
server.printUrls = () => {
original()
const base = server.resolvedUrls?.local[0]
if (base) {
const url = `${base}login?url=${RC_URL}&user=${RC_USER}&pass=${RC_PASS}`
server.config.logger.info(
` \x1b[32m➜\x1b[0m \x1b[1mLogin:\x1b[0m \x1b[36m${url}\x1b[0m`
)
}
}
},
buildEnd() {
rclone?.kill()
rclone = null
},
}
}
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), tailwindcss(), devRclone()],
define: {
APP_VERSION: JSON.stringify(pkg.version),
},
// server: {
// proxy: {
// '/rc': {
// target: 'http://127.0.0.1:5572',
// changeOrigin: true,
// rewrite: (pathname) => pathname.replace(/^\/rc/, ''),
// },
// },
// },
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
build: {
chunkSizeWarningLimit: 1000,
},
})