新增部署专用 Dockerfile.deploy / docker-compose.deploy.yml 与本机构建脚本: 前端 dist 经 go:embed 编入 Go 二进制,alpine 运行时只打包不编译, 旧 Dockerfile 与双容器编排保持不变。
23 lines
564 B
Go
23 lines
564 B
Go
// Package web 通过 go:embed 持有前端构建产物(Vue3 dist)。
|
||
// dist 目录由 Dockerfile 的 node 构建阶段生成到本目录后再编译 Go,
|
||
// 因此最终二进制自带前端,无需独立 Nginx 容器。
|
||
package web
|
||
|
||
import (
|
||
"embed"
|
||
"io/fs"
|
||
)
|
||
|
||
//go:embed all:dist
|
||
var distFS embed.FS
|
||
|
||
// DistFS 返回以 dist 内容为根的只读文件系统。
|
||
func DistFS() (fs.FS, error) {
|
||
return fs.Sub(distFS, "dist")
|
||
}
|
||
|
||
// IndexHTML 返回前端入口页字节。
|
||
func IndexHTML() ([]byte, error) {
|
||
return distFS.ReadFile("dist/index.html")
|
||
}
|