前后端构建逻辑优化:新增Node.js支持,完善Dockerfile,更新构建与验证流程

This commit is contained in:
2026-01-27 15:44:02 +08:00
parent d757dbd39d
commit 89bdfbd48e
8 changed files with 121 additions and 15 deletions

View File

@@ -1,9 +1,22 @@
@echo off
setlocal enabledelayedexpansion
:: 切换到项目根目录
cd /d %~dp0..
set APP_NAME=BingPaper
set OUTPUT_DIR=output
echo 开始构建前端...
cd webapp
call npm install
call npm run build
if %errorlevel% neq 0 (
echo 前端构建失败
exit /b %errorlevel%
)
cd ..
echo 开始构建 %APP_NAME% 多平台二进制文件...
if exist %OUTPUT_DIR% rd /s /q %OUTPUT_DIR%
@@ -25,7 +38,10 @@ for %%p in (%PLATFORMS%) do (
set PACKAGE_DIR=%OUTPUT_DIR%\!OUTPUT_NAME!
if not exist !PACKAGE_DIR! mkdir !PACKAGE_DIR!
env GOOS=%%a GOARCH=%%b CGO_ENABLED=0 go build -o !PACKAGE_DIR!\!BINARY_NAME! main.go
set GOOS=%%a
set GOARCH=%%b
set CGO_ENABLED=0
go build -ldflags="-s -w" -o !PACKAGE_DIR!\!BINARY_NAME! main.go
if !errorlevel! equ 0 (
echo %%a/%%b 编译成功

View File

@@ -1,6 +1,21 @@
# 切换到项目根目录
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
if ($ScriptDir) { Set-Location (Join-Path $ScriptDir "..") }
$AppName = "BingPaper"
$OutputDir = "output"
Write-Host "开始构建前端..."
Push-Location webapp
npm install
npm run build
if ($LASTEXITCODE -ne 0) {
Write-Host "前端构建失败" -ForegroundColor Red
Pop-Location
exit $LASTEXITCODE
}
Pop-Location
Write-Host "开始构建 $AppName 多平台二进制文件..."
if (Test-Path $OutputDir) {
@@ -38,7 +53,7 @@ foreach ($Platform in $Platforms) {
$env:GOOS = $OS
$env:GOARCH = $Arch
$env:CGO_ENABLED = "0"
go build -o (Join-Path $PackageDir $BinaryName) main.go
go build -ldflags="-s -w" -o (Join-Path $PackageDir $BinaryName) main.go
if ($LASTEXITCODE -eq 0) {
Write-Host " $OS/$Arch 编译成功"

View File

@@ -20,6 +20,12 @@ PLATFORMS=(
# 需要包含的额外文件/目录
EXTRA_FILES=("web" "config.example.yaml" "README.md")
echo "开始构建前端..."
cd webapp
npm install
npm run build
cd ..
echo "开始构建 $APP_NAME 多平台二进制文件..."
# 清理 output 目录
@@ -51,7 +57,8 @@ for PLATFORM in "${PLATFORMS[@]}"; do
mkdir -p "$PACKAGE_DIR"
# 现在已移除 CGO 依赖,使用 CGO_ENABLED=0 以支持轻松的跨平台编译
GOOS=$OS GOARCH=$ARCH CGO_ENABLED=0 go build -o "${PACKAGE_DIR}/${BINARY_NAME}" main.go
# 增加 -ldflags="-s -w" 以减少二进制体积
GOOS=$OS GOARCH=$ARCH CGO_ENABLED=0 go build -ldflags="-s -w" -o "${PACKAGE_DIR}/${BINARY_NAME}" main.go
if [ $? -eq 0 ]; then
echo " ${OS}/${ARCH} 编译成功"