Files
eip4-web/vite.config.ts
zhengwr dc9e424d06 F4-L1: amis-editor 页面设计器(多页入口隔离)+overlay 编辑闭环
- editor.html 独立 vite 入口,amis-editor npm 依赖与主应用本地 SDK 隔离
- 设计器:画布编辑/保存→overlay/还原标准版/预览;页面 Tab 管理员「设计」入口
- designer.spec.ts 7 用例(编辑→保存→渲染 overlay→还原,X-Schema-Layer 断言);全套 e2e 68/68

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 04:23:43 +08:00

86 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
// 开发期 dev server 把 /api 反代到后端(默认 8084,端口被占时改 8090)。
// 后端地址经 .env 的 VITE_BACKEND_TARGET 配置;生产由 Nginx 反代,前端只发相对 /api。
//
// F4-L1 多页应用(MPA):
// index.html → 主应用(amis sdk-local UMD)
// editor.html → 设计器(amis npm 包,与主应用隔离)
//
// amis 栈(amis/amis-editor/amis-editor-core/amis-ui/amis-core/amis-formula/i18n-runtime)
// 均为 webpack 产物,package.json 无 exports 字段,vite esbuild pre-bundle 会失败。
// 解法:optimizeDeps.exclude 排出这些包,让 vite 对它们走 native CJS → ESM 转换;
// resolve.alias 把 i18n-runtime 直接指向 lib/index.js(无 exports 字段的包需要手动指向)。
// CSS 由 editor.html <link> 直接引用 /node_modules/... 路径,server.fs.allow 放开目录。
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const backendTarget = env.VITE_BACKEND_TARGET || 'http://localhost:8084';
return {
plugins: [react()],
resolve: {
alias: {
// i18n-runtime 无 exports 字段,vite pre-bundle 无法找到入口;手动指向 lib/index.js
'i18n-runtime': resolve(__dirname, 'node_modules/i18n-runtime/lib/index.js'),
},
},
server: {
port: 5173,
proxy: {
'/api': {
target: backendTarget,
changeOrigin: true,
},
},
// 允许 vite dev server 服务 node_modules 下的静态文件(editor.html 的 CSS link)
fs: {
allow: ['..'],
},
},
build: {
// 产物直接交 Nginx 托管;amis 本地 SDK 在 public/ 下原样拷贝,不参与打包。
outDir: 'dist',
sourcemap: false,
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
editor: resolve(__dirname, 'editor.html'),
},
},
},
optimizeDeps: {
// amis 系列包及其 CJS 传递依赖全部显式 include,让 vite esbuild 统一预构建为 ESM。
// 不用 exclude——exclude 会让传递依赖(如 remove-accents)跳过 CJS→ESM 转换,
// 导致 "does not provide an export named 'default'" 运行时错误。
include: [
'amis',
'amis-editor',
'amis-editor-core',
'amis-ui',
'amis-core',
'amis-formula',
'amis-theme-editor-helper',
'remove-accents',
'classnames',
'lodash',
'hoist-non-react-statics',
'react-is',
'prop-types',
'qs',
'file-saver',
'papaparse',
'ua-parser-js',
'immutability-helper',
'dayjs',
'moment',
'codemirror',
'markdown-it',
'jsbarcode',
'keycode',
'deep-diff',
],
},
};
});