mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-05-28 01:57:25 +08:00
refactor(dev): reorganize dev scripts and port assignments
- dev: Electron only (renderer port 3400, unchanged) - dev:app: Web frontend only (port 3100) - dev:serve: Backend only (chatlab serve, default port 3110) - dev:web: Web frontend + backend auto-start (3100 + 3110) - Revert electron.vite.config.ts to original (no extra plugins) - chatlabServePlugin gated by CHATLAB_AUTO_SERVE env var
This commit is contained in:
@@ -55,7 +55,7 @@ export default defineConfig(() => {
|
||||
ui({
|
||||
ui: {
|
||||
colors: {
|
||||
primary: 'pink', // 使用自定义 pink 作为主色
|
||||
primary: 'pink',
|
||||
neutral: 'zinc',
|
||||
},
|
||||
},
|
||||
|
||||
+3
-1
@@ -28,7 +28,9 @@
|
||||
"build:mac": "pnpm run build && electron-builder --mac --config electron-builder.yml -p never",
|
||||
"build:win": "pnpm run build && electron-builder --win --config electron-builder.yml -p never",
|
||||
"build:linux": "pnpm run build && electron-builder --linux --config electron-builder.yml -p never",
|
||||
"dev:web": "vite --config vite.web.config.mts",
|
||||
"dev:app": "vite --config vite.web.config.mts",
|
||||
"dev:serve": "tsx packages/server/src/cli.ts serve",
|
||||
"dev:web": "CHATLAB_AUTO_SERVE=1 vite --config vite.web.config.mts",
|
||||
"build:web": "vite build --config vite.web.config.mts",
|
||||
"type-check:web": "vue-tsc --noEmit -p tsconfig.web.json",
|
||||
"type-check:node": "tsc --noEmit -p tsconfig.node.json",
|
||||
|
||||
@@ -285,7 +285,7 @@ program
|
||||
program
|
||||
.command('serve')
|
||||
.description('启动独立 HTTP API 服务')
|
||||
.option('--port <port>', '服务端口', '3210')
|
||||
.option('--port <port>', '服务端口', '3110')
|
||||
.option('--host <host>', '监听地址', '127.0.0.1')
|
||||
.option('--token <token>', '自定义 Bearer Token(不指定则从配置文件读取或自动生成)')
|
||||
.option('--web [dir]', '托管 Web 前端静态资源(默认查找 dist-web/)')
|
||||
|
||||
+28
-3
@@ -12,18 +12,43 @@
|
||||
|
||||
import { resolve } from 'path'
|
||||
import { spawn, type ChildProcess } from 'child_process'
|
||||
import * as net from 'net'
|
||||
import { defineConfig, type Plugin } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import ui from '@nuxt/ui/vite'
|
||||
|
||||
const BACKEND_PORT = 3400
|
||||
const BACKEND_PORT = 3110
|
||||
|
||||
function isPortInUse(port: number): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
const server = net.createServer()
|
||||
server.once('error', () => resolve(true))
|
||||
server.once('listening', () => {
|
||||
server.close()
|
||||
resolve(false)
|
||||
})
|
||||
server.listen(port, '127.0.0.1')
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动启动 chatlab serve 后端的插件
|
||||
* 仅在 CHATLAB_AUTO_SERVE=1 时生效(由 dev:web 脚本设置)
|
||||
*/
|
||||
function chatlabServePlugin(): Plugin {
|
||||
let serverProcess: ChildProcess | null = null
|
||||
|
||||
return {
|
||||
name: 'chatlab-serve',
|
||||
configureServer() {
|
||||
async configureServer() {
|
||||
if (process.env.CHATLAB_AUTO_SERVE !== '1') return
|
||||
|
||||
const inUse = await isPortInUse(BACKEND_PORT)
|
||||
if (inUse) {
|
||||
console.log(`[chatlab serve] 端口 ${BACKEND_PORT} 已在使用中,跳过启动`)
|
||||
return
|
||||
}
|
||||
|
||||
const serverDir = resolve(__dirname, 'packages/server')
|
||||
serverProcess = spawn('npx', ['tsx', 'src/cli.ts', 'serve', '--port', String(BACKEND_PORT)], {
|
||||
cwd: serverDir,
|
||||
@@ -105,7 +130,7 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
server: {
|
||||
port: 3401,
|
||||
port: 3100,
|
||||
proxy: {
|
||||
'/_web': `http://localhost:${BACKEND_PORT}`,
|
||||
'/api': `http://localhost:${BACKEND_PORT}`,
|
||||
|
||||
Reference in New Issue
Block a user