12 changed files with 228 additions and 25 deletions
@ -0,0 +1,118 @@
@@ -0,0 +1,118 @@
|
||||
# 🔥 GoFaster 热加载开发指南 |
||||
|
||||
## 概述 |
||||
GoFaster 项目支持前后端热加载,修改代码后无需手动重启服务,大大提高开发效率。 |
||||
|
||||
## 🚀 快速启动 |
||||
|
||||
### 方式1:一键启动(推荐) |
||||
```bash |
||||
# 在项目根目录执行 |
||||
./dev-full.ps1 |
||||
``` |
||||
这将同时启动前后端热加载服务。 |
||||
|
||||
### 方式2:分别启动 |
||||
```bash |
||||
# 启动后端热加载 |
||||
cd backend |
||||
./dev.ps1 |
||||
|
||||
# 启动前端热加载(新终端) |
||||
cd app |
||||
./dev-hot.ps1 |
||||
``` |
||||
|
||||
## 🔧 热加载配置 |
||||
|
||||
### 后端 Go 热加载 |
||||
- **工具**: `air` (Go 热加载工具) |
||||
- **配置文件**: `backend/.air.toml` |
||||
- **监听文件**: `.go`, `.tpl`, `.tmpl`, `.html` |
||||
- **排除目录**: `tmp`, `vendor`, `docs`, `testdata` |
||||
|
||||
### 前端 Electron 热加载 |
||||
- **工具**: `vue-cli-service` + `electron` |
||||
- **配置文件**: `app/vue.config.js` |
||||
- **监听文件**: `.vue`, `.js`, `.css`, `.html` |
||||
- **自动重载**: 代码修改后自动重新编译并重启 Electron |
||||
|
||||
## 📁 文件结构 |
||||
``` |
||||
gofaster/ |
||||
├── dev-full.ps1 # 一键启动脚本 |
||||
├── backend/ |
||||
│ ├── .air.toml # 后端热加载配置 |
||||
│ ├── dev.bat # Windows 后端启动脚本 |
||||
│ └── dev.ps1 # PowerShell 后端启动脚本 |
||||
└── app/ |
||||
├── dev-hot.bat # Windows 前端启动脚本 |
||||
└── dev-hot.ps1 # PowerShell 前端启动脚本 |
||||
``` |
||||
|
||||
## 🎯 使用场景 |
||||
|
||||
### 后端开发 |
||||
1. 修改 Go 代码 |
||||
2. 保存文件 |
||||
3. `air` 自动检测变化 |
||||
4. 自动重新编译并重启服务 |
||||
5. 无需手动重启 |
||||
|
||||
### 前端开发 |
||||
1. 修改 Vue 组件、样式或逻辑 |
||||
2. 保存文件 |
||||
3. `vue-cli-service` 自动重新编译 |
||||
4. Electron 自动重载 |
||||
5. 界面立即更新 |
||||
|
||||
## ⚡ 性能优化 |
||||
|
||||
### 后端优化 |
||||
- 排除测试文件和文档目录 |
||||
- 设置合理的重载延迟(1秒) |
||||
- 只监听必要的文件类型 |
||||
|
||||
### 前端优化 |
||||
- 启用增量编译 |
||||
- 排除不必要的文件监听 |
||||
- 使用内存中的热重载 |
||||
|
||||
## 🐛 故障排除 |
||||
|
||||
### 后端热加载不工作 |
||||
1. 检查 `air` 是否安装:`go version -m $(which air)` |
||||
2. 确认 `.air.toml` 配置正确 |
||||
3. 检查文件权限和路径 |
||||
|
||||
### 前端热加载不工作 |
||||
1. 确认 `npm run dev` 正常运行 |
||||
2. 检查 `vue.config.js` 配置 |
||||
3. 查看控制台错误信息 |
||||
|
||||
### 端口冲突 |
||||
- 后端默认端口:8080 |
||||
- 前端开发端口:3000 |
||||
- 如遇冲突,修改相应配置文件 |
||||
|
||||
## 💡 开发技巧 |
||||
|
||||
1. **保持两个终端窗口**:一个运行后端,一个运行前端 |
||||
2. **使用 VS Code 集成终端**:方便同时查看前后端日志 |
||||
3. **合理使用日志**:热重载时日志会保留,便于调试 |
||||
4. **测试验证码接口**:修改后端代码后,验证码接口会立即生效 |
||||
|
||||
## 🔄 热加载流程 |
||||
|
||||
``` |
||||
修改代码 → 保存文件 → 自动检测 → 重新编译 → 重启服务 → 立即生效 |
||||
``` |
||||
|
||||
## 📚 相关文档 |
||||
- [Air 官方文档](https://github.com/air-verse/air) |
||||
- [Vue CLI 热重载](https://cli.vuejs.org/guide/cli-service.html#vue-cli-service-serve) |
||||
- [Electron 开发指南](https://www.electronjs.org/docs/tutorial/development) |
||||
|
||||
--- |
||||
|
||||
**享受高效的开发体验!** 🎉 |
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
@echo off |
||||
echo Starting GoFaster Frontend with Hot Reload... |
||||
echo. |
||||
echo Hot reload enabled - code changes will automatically rebuild and reload |
||||
echo Press Ctrl+C to stop |
||||
echo. |
||||
|
||||
npm run dev |
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
Write-Host "Starting GoFaster Frontend with Hot Reload..." -ForegroundColor Green |
||||
Write-Host "" |
||||
Write-Host "Hot reload enabled - code changes will automatically rebuild and reload" -ForegroundColor Yellow |
||||
Write-Host "Press Ctrl+C to stop" -ForegroundColor Yellow |
||||
Write-Host "" |
||||
|
||||
npm run dev |
@ -1,21 +1,44 @@
@@ -1,21 +1,44 @@
|
||||
root = "." |
||||
testdata_dir = "testdata" |
||||
tmp_dir = "tmp" |
||||
|
||||
[build] |
||||
cmd = "go build -o ./tmp/main.exe ." |
||||
args_bin = ["-v"] |
||||
bin = "./tmp/main.exe" |
||||
runner = ["./tmp/main.exe"] |
||||
include_ext = ["go", "tpl", "tmpl", "html"] |
||||
exclude_dir = ["assets", "tmp", "vendor", "docs"] |
||||
args_bin = [] |
||||
bin = "./tmp/main.exe" |
||||
cmd = "go build -o ./tmp/main.exe ." |
||||
delay = 1000 |
||||
exclude_dir = ["assets", "tmp", "vendor", "testdata", "docs"] |
||||
exclude_file = [] |
||||
exclude_regex = ["_test.go"] |
||||
exclude_unchanged = false |
||||
follow_symlink = false |
||||
full_bin = "" |
||||
include_dir = [] |
||||
include_ext = ["go", "tpl", "tmpl", "html"] |
||||
include_file = [] |
||||
kill_delay = "0s" |
||||
log = "build-errors.log" |
||||
poll = false |
||||
poll_interval = 0 |
||||
rerun = false |
||||
rerun_delay = 500 |
||||
send_interrupt = false |
||||
stop_on_root = false |
||||
|
||||
[color] |
||||
app = "" |
||||
build = "yellow" |
||||
main = "magenta" |
||||
runner = "green" |
||||
watcher = "cyan" |
||||
|
||||
[log] |
||||
time = true |
||||
level = "debug" |
||||
main_only = false |
||||
time = false |
||||
|
||||
[misc] |
||||
clean_on_exit = true |
||||
clean_before_build = true |
||||
clean_on_exit = false |
||||
|
||||
[windows] |
||||
filter_extension = ["exe", "dll", "so", "a"] |
||||
[screen] |
||||
clear_on_rebuild = false |
||||
keep_scroll = true |
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
@echo off |
||||
echo Starting GoFaster Backend with Hot Reload... |
||||
echo. |
||||
echo Hot reload enabled - code changes will automatically restart the server |
||||
echo Press Ctrl+C to stop |
||||
echo. |
||||
|
||||
air |
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
Write-Host "Starting GoFaster Backend with Hot Reload..." -ForegroundColor Green |
||||
Write-Host "" |
||||
Write-Host "Hot reload enabled - code changes will automatically restart the server" -ForegroundColor Yellow |
||||
Write-Host "Press Ctrl+C to stop" -ForegroundColor Yellow |
||||
Write-Host "" |
||||
|
||||
air |
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
Write-Host "🚀 Starting GoFaster Full Stack Development Environment..." -ForegroundColor Cyan |
||||
Write-Host "" |
||||
Write-Host "Frontend: Electron + Vue.js with Hot Reload" -ForegroundColor Green |
||||
Write-Host "Backend: Go + Gin with Hot Reload" -ForegroundColor Green |
||||
Write-Host "" |
||||
Write-Host "Press Ctrl+C to stop all services" -ForegroundColor Yellow |
||||
Write-Host "" |
||||
|
||||
# 启动后端热加载(后台运行) |
||||
Write-Host "Starting Backend with Hot Reload..." -ForegroundColor Green |
||||
Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd backend; air" -WindowStyle Normal |
||||
|
||||
# 等待2秒让后端启动 |
||||
Start-Sleep -Seconds 2 |
||||
|
||||
# 启动前端热加载(后台运行) |
||||
Write-Host "Starting Frontend with Hot Reload..." -ForegroundColor Green |
||||
Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd app; npm run dev" -WindowStyle Normal |
||||
|
||||
Write-Host "" |
||||
Write-Host "✅ Both services started successfully!" -ForegroundColor Green |
||||
Write-Host "Frontend: http://localhost:3000 (Electron app)" -ForegroundColor Cyan |
||||
Write-Host "Backend: http://localhost:8080" -ForegroundColor Cyan |
||||
Write-Host "Swagger: http://localhost:8080/swagger/index.html" -ForegroundColor Cyan |
||||
Write-Host "" |
||||
Write-Host "💡 Code changes will automatically trigger rebuilds and reloads!" -ForegroundColor Yellow |
||||
Write-Host "Press any key to exit this launcher..." |
||||
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") |
Loading…
Reference in new issue