chore: 优化前端构建方式

This commit is contained in:
2025-12-20 22:01:51 +08:00
parent e0822528a7
commit 93688a0e4e
3 changed files with 31 additions and 21 deletions

4
apps/.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
node_modules
.next
.git
.env.local

View File

@@ -1,28 +1,33 @@
FROM node:22-alpine AS builder
RUN npm install -g pnpm
WORKDIR /app
COPY package*.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY . .
ARG API_BASE
ENV API_BASE=$API_BASE
RUN pnpm run build
FROM node:22-alpine
# 安装依赖
FROM node:22-alpine AS deps
RUN apk add --no-cache libc6-compat
RUN npm install -g pnpm
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --prod
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.ts ./
RUN pnpm install --frozen-lockfile
# 编译
FROM node:22-alpine AS builder
RUN npm install -g pnpm
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ARG API_BASE
ENV API_BASE=$API_BASE
RUN pnpm run build
# 运行
FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ARG API_BASE
ENV API_BASE=$API_BASE
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
EXPOSE 3000
CMD ["pnpm", "start"]
CMD ["node", "server.js"]

View File

@@ -2,6 +2,7 @@ import type { NextConfig } from "next";
const nextConfig: NextConfig = {
/* config options here */
output: 'standalone',
reactStrictMode: true,
devIndicators: {
position: 'bottom-right',
@@ -16,7 +17,7 @@ const nextConfig: NextConfig = {
},
images: {
remotePatterns: [new URL('https://tone-personal.oss-cn-chengdu.aliyuncs.com/**')]
}
},
};
export default nextConfig;