Files
yunzerwebsiteallinone/uniapp/vite.config.js
T
2026-10-31 19:17:37 +08:00

58 lines
1.6 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 } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
// 新版 Vite / uni 编译器会把配置文件预打包成 CJS 加载,此时 import.meta.url 为 undefined,
// fileURLToPath(undefined) 会抛 "The path argument must be of type string. Received undefined"。
// 这里做兜底:拿不到模块路径时退回 __dirname / 当前工作目录(构建命令均在 uniapp 目录执行)。
function resolveRootDir() {
try {
const url = typeof import.meta !== 'undefined' ? import.meta.url : ''
if (url) return path.dirname(fileURLToPath(url))
} catch (e) {
/* import.meta.url 不可用时继续兜底 */
}
try {
if (typeof __dirname !== 'undefined') return __dirname
} catch (e) {
/* 忽略 */
}
return process.cwd()
}
const rootDir = resolveRootDir()
export default defineConfig({
base: '/h5/',
plugins: [uni()],
resolve: {
alias: {
'@': rootDir,
},
},
server: {
host: '127.0.0.1',
port: 4403,
strictPort: true,
proxy: {
// H5 开发:api/config.js 默认 baseURL 为 /proxy-api,转发到 Go 后端
'/proxy-api': {
// 本地联调统一认证(/app/home 等新接口生产未部署时用本地)
target: 'http://127.0.0.1:9000',
// target: 'https://api.yunzer.cn',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/proxy-api/, ''),
},
},
},
css: {
preprocessorOptions: {
scss: {
// 关闭废弃 API 警告
silenceDeprecations: ['legacy-js-api', 'color-functions', 'import'],
},
},
},
})