build: support running the server with go run during development

- The dev build tag reads web/dist from disk instead of embedding it,
  so the backend starts without building the frontend first; Vite
  serves the UI and proxies /api and WebSocket to the Go server
- Document the two-terminal dev workflow and ignore .dev-data/
This commit is contained in:
eezd committed 2026-10-16 18:46:13 +08:00
1 parent bfe0a0654d
commit dc7e43bc3c
4 files changed
+36 -4

No files matched your search

+3
View File
@@ -5,3 +5,6 @@ docs/
# 前端 # 前端
node_modules/ node_modules/
web/dist/ web/dist/
# 本地开发数据
.dev-data/
+16 -4
View File
@@ -28,9 +28,21 @@ docker run -d --name rawmark \
## 开发 ## 开发
需要 Go 1.27+ 与 Node 24+。开发时不必构建前端或 Docker 镜像,开两个终端:
```sh ```sh
cd web && npm install # 终端 1:后端(-tags dev 不嵌入前端资源,数据放在仓库下的 .dev-data/)
npm run dev # 前端开发服务器,/api 转发到 127.0.0.1:8080 RAWMARK_DATA=.dev-data RAWMARK_ADDR=127.0.0.1:8080 go run -tags dev ./cmd/rawmark
npm run typecheck && npm test
go test ./internal/... # 终端 2:前端(热更新,/api 与 WebSocket 转发到 127.0.0.1:8080)
cd web && npm install && npm run dev
```
浏览器打开 http://localhost:5173 ,启动码在 `.dev-data/setup-code.txt`。手机调试用 `npm run dev -- --host`,再访问 `http://<电脑 IP>:5173`。
检查:
```sh
cd web && npm run typecheck && npm test
go vet -tags dev ./... && go test ./internal/...
``` ```
+3
View File
@@ -1,4 +1,7 @@
//go:build !dev
// Package web 把前端构建产物(web/dist,由 npm run build 生成)嵌入 Go 二进制。 // Package web 把前端构建产物(web/dist,由 npm run build 生成)嵌入 Go 二进制。
// 开发时使用 -tags dev,前端由 Vite 开发服务器提供,见 embed_dev.go。
package web package web
import ( import (
+14
View File
@@ -0,0 +1,14 @@
//go:build dev
package web
import (
"io/fs"
"os"
)
// Dist 在开发模式下直接读取磁盘上的 web/dist(未构建时为空,页面由 Vite 开发服务器提供),
// 因此无需先构建前端即可 go run
func Dist() fs.FS {
return os.DirFS("web/dist")
}