// vite.config.js（正确的 CommonJS 配置）
const {
	defineConfig
} = require("vite");
const uni = require("@dcloudio/vite-plugin-uni").default; // uni 插件需要 .default
const AutoImport = require("unplugin-auto-import/vite"); // 旧版本 AutoImport 直接导出函数，无需 .default

module.exports = defineConfig({
	plugins: [
		uni(),
		AutoImport({
			include: [/\.js$/, /\.vue$/, /\.vue\?vue/],
			imports: [
				"vue",
				{
					"@dcloudio/uni-app": [
						"onShareAppMessage",
						"onShareTimeline",
						"onLoad",
						"onShow",
						"onHide",
						"onUnload",
						"onReady",
						"onReachBottom",
						"onPageScroll",
						"uni.request",
						"uni.navigateTo",
						"uni.showToast",
					],
				},
			],
			dts: "src/auto-imports.d.ts",
		}),
	],
	server: {
		proxy: {
			'/testApi': {
				// target: 'https://cashier.sxczgkj.com', // 目标服务器地址
				target: 'http://192.168.1.42/', // 目标服务器地址
				changeOrigin: true, // 是否更改请求源
				rewrite: path => path.replace(/^\/testApi/, '')
			},
			'/prodApi': {
				target: 'https://cashier.sxczgkj.com', // 目标服务器地址
				changeOrigin: true, // 是否更改请求源
				rewrite: path => path.replace(/^\/prodApi/, '')
			},
		},
	},
});