CRMEB/frontend/uni-app/vite.config.js
吴昊天 d2d1305d26 fix(礼物海报): 修复保存海报空白并同源化绘制图片
- 组件内置离屏画布并按组件实例创建上下文,补齐缺失的海报画布
- 头像/二维码缺失时跳过绘制,二维码异步生成等待后再绘制
- 失败时提示海报生成失败,关闭弹窗重置海报状态
- 开发环境代理 /uploads、/statics,规避 canvas 跨域污染
2026-10-21 16:26:36 +08:00

33 lines
1.3 KiB
JavaScript
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 uni from '@dcloudio/vite-plugin-uni';
import { installAutoSubpackages, uniAutoSubpackagesPlugin } from './scripts/uni-auto-subpackages.mjs';
export default defineConfig(({ mode }) => {
// 读取根目录 .env / .env.[mode] 中自定义的 UNI_APP_* 变量
// (vite 的 loadEnv 默认只取 VITE_ 前缀,第三个参数传 '' 表示取全部)
const env = loadEnv(mode, process.cwd(), '');
// 把 src/pages-modules/ 模块分包在内存中合并进 pages.json 的读取(磁盘文件不变);
// 必须在 uni() 首次读取 pages.json 之前执行
installAutoSubpackages();
// 开发环境后端地址:海报等场景需要同源读取后端静态资源(避免 canvas 跨域污染)
const apiTarget = env.UNI_APP_API_URL || 'http://127.0.0.1:8011';
return {
plugins: [uniAutoSubpackagesPlugin(), uni()],
server: {
proxy: {
// 后台上传文件(商品图等)
'/uploads': { target: apiTarget, changeOrigin: true },
// 后端系统静态图(海报背景、礼物边框等)
'/statics': { target: apiTarget, changeOrigin: true }
}
},
define: {
// 注入 src/config/app.js 中使用的接口地址变量;.env 未配置时置空串,代码内回退到各端默认值
'process.env.UNI_APP_API_URL': JSON.stringify(env.UNI_APP_API_URL || '')
}
};
});