From 4e8ff8d777640ee3f232c623540839fee3afab34 Mon Sep 17 00:00:00 2001 From: 17792275749 <812100002@qq.com> Date: Fri, 6 Feb 2026 10:24:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=20docker=20?= =?UTF-8?q?=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 17 +++++++++++++++++ nginx.conf | 23 +++++++++++++++++++++++ vue.config.js | 4 ++-- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..109cc85 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +# 1. 第一阶段:构建 +FROM node:20-alpine AS builder + +WORKDIR /app + +COPY package*.json ./ +RUN npm install + +COPY . . + +# 2. 根据 MODE 参数执行对应的打包命令 +RUN npm run build + +# 2. 第二阶段:部署 +FROM nginx:stable-alpine +COPY --from=builder /app/dist /usr/share/nginx/html +COPY ./nginx.conf /etc/nginx/conf.d/default.conf \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..3d36427 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,23 @@ +server { + listen 80; + listen [::]:80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html; + + # 针对 HTML 文件设置不缓存 + if ($request_filename ~* .*\.(?:htm|html)$ ) { + add_header Cache-Control "no-cache, no-store, must-revalidate"; + } + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} + + diff --git a/vue.config.js b/vue.config.js index 301a217..4fef609 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,8 +1,8 @@ const webpack = require('webpack'); module.exports = { - publicPath: '/plus-6/', - outputDir: "dist", + // publicPath: '/plus-6/', + // outputDir: "dist", transpileDependencies: true, productionSourceMap: false, devServer: {