File tree Expand file tree Collapse file tree 2 files changed +26
-20
lines changed
Expand file tree Collapse file tree 2 files changed +26
-20
lines changed Original file line number Diff line number Diff line change 1- FROM node:20-alpine AS dependencies-env
1+ # 建置階段
2+ FROM node:20-alpine AS build
23RUN npm i -g pnpm
3- COPY . /app
4-
5- FROM dependencies-env AS development-dependencies-env
6- COPY ./package.json pnpm-lock.yaml /app/
74WORKDIR /app
8- RUN pnpm i --frozen-lockfile
95
10- FROM dependencies-env AS production-dependencies-env
11- COPY ./package.json pnpm-lock.yaml /app/
12- WORKDIR /app
13- RUN pnpm i --prod --frozen-lockfile
6+ # 安裝依賴
7+ COPY package.json pnpm-lock.yaml ./
8+ RUN pnpm i --frozen-lockfile
149
15- FROM dependencies-env AS build-env
16- COPY ./package.json pnpm-lock.yaml /app/
17- COPY --from=development-dependencies-env /app/node_modules /app/node_modules
18- WORKDIR /app
10+ # 複製源碼並建置
11+ COPY . .
1912RUN pnpm build
2013
21- FROM dependencies-env
22- COPY ./package.json pnpm-lock.yaml /app/
23- COPY --from=production-dependencies-env /app/node_modules /app/node_modules
24- COPY --from=build-env /app/build /app/build
25- WORKDIR /app
26- CMD ["pnpm" , "start" ]
14+ # 生產環境 - 使用 nginx 來服務靜態檔案
15+ FROM nginx:alpine
16+ # 複製 nginx 配置
17+ COPY nginx.conf /etc/nginx/conf.d/default.conf
18+ # 複製建置檔案到 nginx 的服務目錄
19+ COPY --from=build /app/build/client /usr/share/nginx/html
20+
21+ # nginx 預設會在 80 port 啟動
22+ EXPOSE 80
23+ CMD ["nginx" , "-g" , "daemon off;" ]
Original file line number Diff line number Diff line change 1+ server {
2+ listen 80 ;
3+
4+ location / {
5+ root /usr/share/nginx/html;
6+ try_files $uri $uri / /index .html;
7+ index index .html;
8+ }
9+ }
You can’t perform that action at this time.
0 commit comments