Commit c68b08da by zhangxingmin

push

parent c972c432
# 第一阶段:构建项目
FROM node:16-alpine AS builder
# 设置工作目录
WORKDIR /app
# 替换国内镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 从构建上下文的软链接复制 HBuilderX 到容器(关键修改)
COPY ./HBuilderX /opt/HBuilderX
# 赋予执行权限
RUN chmod -R 755 /opt/HBuilderX
# 复制依赖文件
COPY package.json package-lock.json ./
# 安装依赖
RUN npm config set registry https://registry.npmmirror.com \
&& npm install --production
# 复制源代码
COPY . .
# 执行打包(使用容器内的 HBuilderX)
RUN npm run build:h5 \
&& echo "构建产物目录结构:" \
&& ls -R /app/dist
# 生产阶段(不变)
FROM docker.m.daocloud.io/library/nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 时区和权限配置(不变)
RUN echo "https://mirrors.aliyun.com/alpine/v3.22/main/" > /etc/apk/repositories && \
echo "https://mirrors.aliyun.com/alpine/v3.22/community/" >> /etc/apk/repositories && \
apk update && \
apk add --no-cache tzdata && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
RUN chown -R nginx:nginx /usr/share/nginx/html \
&& chmod -R 755 /usr/share/nginx/html
EXPOSE 8333
CMD ["nginx", "-g", "daemon off;"]
# 使用官方Nginx镜像
FROM nginx:alpine
# 删除默认配置
RUN rm /etc/nginx/conf.d/default.conf
# 复制自定义Nginx配置
COPY jenkins/nginx.conf /etc/nginx/conf.d/app.conf
# 复制H5构建产物
COPY dist /usr/share/nginx/html
# 暴露端口
EXPOSE 8333
# 启动Nginx(非后台模式)
CMD ["nginx", "-g", "daemon off;"]
server { server {
listen 8333; listen 8333;
server_name localhost; server_name localhost;
root /usr/share/nginx/html; # 直接指向资源所在的根目录
index index.html;
# 静态资源处理(匹配实际 assets 目录)
location ~* \.(js|css|png|jpg|svg|woff2?|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public";
access_log off;
}
# 主应用路由(history 模式)
location / { location / {
try_files $uri $uri/ /index.html; root /usr/share/nginx/html;
add_header Cache-Control "no-store, no-cache, must-revalidate"; index index.html;
try_files $uri $uri/ /index.html; # 支持Vue路由History模式
} }
# 错误处 # 可选:API代
error_page 500 502 503 504 /50x.html; location /api {
location = /50x.html { proxy_pass http://backend-service;
root /usr/share/nginx/html; proxy_set_header Host $host;
} }
} }
...@@ -14,26 +14,14 @@ ...@@ -14,26 +14,14 @@
"通用组件" "通用组件"
] ]
}, },
"scripts": {
"dev": "vite",
"build": "vite build",
"build:h5": "/opt/HBuilderX/HBuilderX -c build -p h5 -d /app/dist",
"preview": "vite preview"
},
"dependencies": { "dependencies": {
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
"dayjs": "^1.11.13", "dayjs": "^1.11.13",
"echarts": "^5.4.1", "echarts": "^5.4.1",
"js-sha256": "^0.11.1", "js-sha256": "^0.11.1",
"nanoid": "^4.0.0", "nanoid": "^4.0.0"
"vue": "^2.6.14",
"vue-router": "^3.5.4"
}, },
"devDependencies": { "devDependencies": {
"vite": "3.2.7",
"vite-plugin-vue2": "^2.0.3",
"vue-template-compiler": "^2.6.14",
"terser": "^5.26.0",
"less": "^4.3.0" "less": "^4.3.0"
} }
} }
import { defineConfig } from 'vite'
import { createVuePlugin } from 'vite-plugin-vue2'
import path from 'path'
export default defineConfig({
// 根路径配置,与 Nginx 保持一致
base: '/',
plugins: [
// 配置 Vue 2 插件
createVuePlugin({
vueTemplateOptions: {
compilerOptions: {
// 针对 Vue 2 的模板编译选项
whitespace: 'condense'
}
}
})
],
resolve: {
extensions: ['.vue', '.js', '.ts', '.json'],
alias: {
'@': path.resolve(__dirname),
'@api': path.resolve(__dirname, 'api'),
// 确保 Vue 2 正确解析
'vue': 'vue/dist/vue.runtime.common.js'
}
},
// 开发服务器配置
server: {
port: 8080,
proxy: {
// 代理后端 API 请求
'/cffpApi': {
target: 'http://localhost:8080', // 修改为实际后端地址
changeOrigin: true,
rewrite: (path) => path.replace(/^\/cffpApi/, '')
}
}
},
build: {
outDir: 'dist',
assetsDir: 'assets',
// 生成 manifest 文件,便于追踪资源
manifest: true,
// 压缩代码
minify: 'terser',
// 禁用哈希和合并
rollupOptions: {
output: {
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
assetFileNames: '[name].[ext]', // 保持原名
manualChunks: null // 禁用依赖合并
}
}
},
// 生产环境移除 console
esbuild: {
drop: ['console', 'debugger']
}
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment