From a86e8a2c67710b716bf675f7bdf4aa8d3bc6e5ce Mon Sep 17 00:00:00 2001 From: kang Date: Tue, 7 Jul 2026 15:32:03 +0800 Subject: [PATCH] =?UTF-8?q?chore(deploy):=20=E5=AE=8C=E5=96=84=20lotteryfr?= =?UTF-8?q?ont=20=E5=8D=95=E6=9C=BA=E9=83=A8=E7=BD=B2=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecosystem.config.cjs | 8 ++++---- next.config.ts | 2 ++ package.json | 2 +- scripts/deploy.sh | 21 +++++++++++++++++++++ 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 scripts/deploy.sh diff --git a/ecosystem.config.cjs b/ecosystem.config.cjs index 4ceadfe..78365d2 100644 --- a/ecosystem.config.cjs +++ b/ecosystem.config.cjs @@ -3,8 +3,8 @@ * 玩家端(lotteryfront)宝塔 PM2 配置 * * 部署步骤(在服务器项目目录执行): - * 1. 复制 .env.example 为 .env,按线上域名填写(见下方 env 说明) - * 2. npm ci && npm run build + * 1. 本地 npm run build,打包 .next/standalone + .next/static + public 上传服务器 + * 2. 服务器:复制 .env.example 为 .env,按线上域名填写(见下方 env 说明) * 3. 修改下方 cwd 为服务器上的实际路径 * 4. pm2 start ecosystem.config.cjs * 5. pm2 save && pm2 startup # 开机自启(按 PM2 提示执行) @@ -23,8 +23,7 @@ module.exports = { { name: "lotteryfront", cwd: APP_CWD, - script: "node_modules/next/dist/bin/next", - args: "start -p 3800 -H 127.0.0.1", + script: ".next/standalone/server.js", interpreter: "node", exec_mode: "fork", instances: 1, @@ -38,6 +37,7 @@ module.exports = { env: { NODE_ENV: "production", + HOSTNAME: "0.0.0.0", PORT: "3800", }, diff --git a/next.config.ts b/next.config.ts index 3724fce..c7f66b7 100644 --- a/next.config.ts +++ b/next.config.ts @@ -6,10 +6,12 @@ import { parseAllowedDevOrigins } from "./src/lib/next-dev-origins"; const allowedDevOrigins = parseAllowedDevOrigins(process.env.ALLOWED_DEV_ORIGINS); const nextConfig: NextConfig = { + output: "standalone", allowedDevOrigins, reactCompiler: true, images: { + unoptimized: true, deviceSizes: [640, 750, 828, 1080, 1200, 1920], }, diff --git a/package.json b/package.json index b750168..bf6db76 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "next dev --port 3800 -H 0.0.0.0", - "build": "next build", + "build": "next build && cp -r .next/static .next/standalone/.next/static && cp -r public .next/standalone/public && echo '✅ standalone 静态资源已复制完毕'", "start": "next start --port 3800", "lint": "eslint" }, diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100644 index 0000000..6c8a0e6 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# lotteryfront 一键部署脚本 +# 用法: bash scripts/deploy.sh + +set -e + +SERVER="root@47.242.205.221" +REMOTE_DIR="/www/wwwroot/lotteryFront" + +echo "🔨 构建中..." +npm run build + +echo "📦 上传到服务器..." +ssh ${SERVER} "mkdir -p ${REMOTE_DIR}/.next/standalone ${REMOTE_DIR}/logs" +rsync -avz --delete .next/standalone/ ${SERVER}:${REMOTE_DIR}/.next/standalone/ +rsync -avz ecosystem.config.cjs ${SERVER}:${REMOTE_DIR}/ecosystem.config.cjs + +echo "🚀 服务器重启 PM2..." +ssh ${SERVER} "source /etc/profile && source ~/.bashrc && mkdir -p ${REMOTE_DIR}/logs && cd ${REMOTE_DIR} && (pm2 restart lotteryfront 2>/dev/null || pm2 start ecosystem.config.cjs) && pm2 save" + +echo "✅ lotteryFront 部署完成!"