From 37298186eb2ae95cfbcd7b6f25213521b5d8f4e7 Mon Sep 17 00:00:00 2001 From: zhengwr Date: Fri, 19 Jun 2026 22:54:46 +0800 Subject: [PATCH] chore(build): add preview proxy for local production-build verification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 验证「设计器生产构建是否裂」时需要本地托管 dist 并能访问后端。`vite preview` 默认不带 /api 反代,补 preview.proxy(与 server.proxy 同口径,走 .env.local 的 VITE_BACKEND_TARGET)→ 可本地跑 `npm run preview` 验证 prod 构建。 结论(实测):生产构建本就安全——editor.html 源里 3 个 /node_modules CSS 直链在 vite build 时被解析+打包进 dist/assets/editor-*.css(2.3MB,含完整 amis-editor/ amis-ui 样式,1742×.ae- / 12155×.cxd-),dist/editor.html 零 /node_modules 残留; preview 托管 dist 实测编辑器三栏完整带样式渲染(panelCount 123)、高度约束修复 生效(aeEditor 831px/clippedLayers 0)、schema 经 proxy 加载。memory「生产可能裂」 顾虑证伪。 Co-Authored-By: Claude Opus 4.8 (1M context) --- vite.config.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vite.config.ts b/vite.config.ts index 3d2a1eb..8870c98 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -38,6 +38,16 @@ export default defineConfig(({ mode }) => { allow: ['..'], }, }, + // `npm run preview` 托管 dist 产物时也把 /api 反代到后端,便于本地验证生产构建 + // (生产真部署由 Nginx 反代 /api;此处仅本地 prod-build 验证用,与 server.proxy 同口径)。 + preview: { + proxy: { + '/api': { + target: backendTarget, + changeOrigin: true, + }, + }, + }, build: { // 产物直接交 Nginx 托管;amis 本地 SDK 在 public/ 下原样拷贝,不参与打包。 outDir: 'dist',