fix: Make Dockerfile tolerant of missing package-lock.json
The initial project has no node_modules or package-lock.json yet. Use wildcard COPY for lock file and fallback to `npm install` when lock file doesn't exist. Once lock file is generated and committed, it will automatically use the faster `npm ci`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6b90d61199
commit
79689c5f95
|
|
@ -3,11 +3,12 @@ FROM node:20-alpine AS deps
|
||||||
RUN apk add --no-cache libc6-compat
|
RUN apk add --no-cache libc6-compat
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# 复制依赖文件
|
# 复制依赖文件 (lock文件可选,首次构建会自动生成)
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json ./
|
||||||
|
COPY package-lock.json* ./
|
||||||
|
|
||||||
# 安装依赖
|
# 安装依赖 (有lock文件用ci,没有则用install)
|
||||||
RUN npm ci --only=production=false
|
RUN if [ -f package-lock.json ]; then npm ci; else npm install; fi
|
||||||
|
|
||||||
# 阶段2: 构建
|
# 阶段2: 构建
|
||||||
FROM node:20-alpine AS builder
|
FROM node:20-alpine AS builder
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue