配合 zTools2 路由统一到 /api/,简化环境感知配置:
- app.config.js:去掉 BASE_URL 的 dev/prod 分支,iframe 与探针一律用同源相对路径
(/api/pdf、/api/health、/api/wb-page/{id}),默认空 baseUrl;保留 VITE_API_BASE 覆盖。
这样无论 dev(vite proxy)还是任意部署环境(反代),同源相对路径都自动指向当前环境 zTools2,
不再误打到 f.zikai.wang 等其它环境域名。
- vite.config.js:dev proxy 从 /api /pdf /health /static /upload /files /wb /ws 多条
简化为单条 /api(含 ws:true,覆盖 /api/ws WebSocket)。
- deploy.sh:Apache vhost 从多条 ProxyPass 简化为单条 /api/,a2enmod 增加 proxy_wstunnel。
- docs/deployment.md:更新拓扑/模式说明,新增路由约定(所有入口在 /api/ 下,反代只需一条规则)。
- 同步更新 zPDF_package 子模块指针(其 vite proxy 亦简化为单条 /api)。
77 lines
2.5 KiB
JavaScript
77 lines
2.5 KiB
JavaScript
import { defineConfig } from 'vite'
|
||
import vue from '@vitejs/plugin-vue'
|
||
import { minify } from 'html-minifier-terser'
|
||
|
||
// 构建到项目本地 dist/(每次清空,避免旧产物残留),
|
||
// 再由 `npm run deploy` 用 rsync 同步到 Apache 站点根 /root/html(软链到 /var/www/html)。
|
||
// 文件名去掉内容 hash,保持稳定;JS 由 esbuild 压缩,HTML 由下方插件压缩。
|
||
// 用 mainPage/ 命名空间子目录避免与 /root/html/js、/root/html/css 既有旧文件冲突。
|
||
function minifyHtml() {
|
||
return {
|
||
name: 'minify-html',
|
||
apply: 'build',
|
||
transformIndexHtml: {
|
||
order: 'post',
|
||
handler(html) {
|
||
return minify(html, {
|
||
collapseWhitespace: true,
|
||
removeComments: true,
|
||
removeRedundantAttributes: true,
|
||
removeScriptTypeAttributes: true,
|
||
removeStyleLinkTypeAttributes: true,
|
||
collapseBooleanAttributes: true,
|
||
minifyCSS: true,
|
||
minifyJS: true,
|
||
})
|
||
},
|
||
},
|
||
}
|
||
}
|
||
|
||
export default defineConfig({
|
||
plugins: [vue(), minifyHtml()],
|
||
base: '/',
|
||
build: {
|
||
outDir: 'dist',
|
||
// ★ dist 在项目内,安全清空,杜绝旧 hash 文件堆积
|
||
emptyOutDir: true,
|
||
rollupOptions: {
|
||
output: {
|
||
// 稳定文件名:去掉 [hash],便于部署与长效缓存策略
|
||
entryFileNames: 'js/mainPage/[name].js',
|
||
chunkFileNames: 'js/mainPage/[name].js',
|
||
assetFileNames: (assetInfo) => {
|
||
const name = assetInfo.name || ''
|
||
if (name.endsWith('.css')) {
|
||
return 'css/mainPage/[name][extname]'
|
||
}
|
||
return 'assets/mainPage/[name][extname]'
|
||
},
|
||
},
|
||
},
|
||
},
|
||
server: {
|
||
// 开发服务器把站点根的静态资源代理到 /root/html,方便引用 /448 /449 等
|
||
port: 5173,
|
||
proxy: {
|
||
'/448': {
|
||
target: 'http://localhost:8080',
|
||
changeOrigin: true,
|
||
},
|
||
'/449': {
|
||
target: 'http://localhost:8080',
|
||
changeOrigin: true,
|
||
},
|
||
// zTools2 后端同源代理:所有入口(页面/静态/探针/WS/API)统一在 /api/ 下,
|
||
// 一条 /api 规则即可覆盖 iframe(/api/pdf)与 fetch(/api/pdf/*)。
|
||
// ws:true 让 /api/ws/wb/{id} 的 WebSocket 也走此代理。
|
||
// 同源相对路径与环境无关:dev 命中本地 zTools2,生产由反代命中当前环境 zTools2。
|
||
'/api': {
|
||
target: 'http://127.0.0.1:6867',
|
||
changeOrigin: true,
|
||
ws: true,
|
||
},
|
||
},
|
||
},
|
||
})
|