Files
kefu/admin-web/apps/mobile-h5/vite.config.ts
T
2026-09-29 15:52:07 +08:00

47 lines
1.6 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 { fileURLToPath, URL } from 'node:url';
import vue from '@vitejs/plugin-vue';
import { defineConfig, type Plugin } from 'vite';
// Vant 的图标字体同时写了内嵌的 woff2 和一个阿里 CDN 的 woff 兜底。内嵌那份总能用;
// 外链只会在内网环境里失败,并被页面的 CSP(font-src 'self' data:)拦下报错。
// 在打包前改写源 CSS,文件名里的内容哈希才会跟着变,浏览器缓存不会拿到旧内容。
function dropRemoteIconFont(): Plugin {
const remote = /,\s*url\(["']?\/\/at\.alicdn\.com[^)]*\)\s*format\(["']?woff["']?\)/g;
return {
name: 'drop-remote-icon-font',
enforce: 'pre',
transform(code, id) {
if (!id.split('?')[0].endsWith('.css') || !code.includes('at.alicdn.com')) return null;
return { code: code.replace(remote, ''), map: null };
},
};
}
// 构建产物由管理端 admin_api.py 托管在 /m/,与 /api/v2/mobile/* 同源。
// 开发时把 /api 代理到本机后台(默认 8766,可用 MOBILE_API_TARGET 覆盖)。
export default defineConfig({
base: '/m/',
plugins: [vue(), dropRemoteIconFont()],
resolve: {
alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) },
},
build: {
outDir: 'dist',
assetsDir: 'assets',
// 企业微信 / 微信内置浏览器和老一点的 iOS Safari 也要能打开。
target: ['es2019', 'safari13', 'chrome80'],
sourcemap: false,
},
server: {
host: '127.0.0.1',
port: 5190,
proxy: {
'/api': {
target: process.env.MOBILE_API_TARGET || 'http://127.0.0.1:8766',
changeOrigin: false,
},
},
},
});