import vue from '@vitejs/plugin-vue';
import Components from 'unplugin-vue-components/vite';
import path from 'path';
import {
    VantResolver
} from 'unplugin-vue-components/resolvers';
import commonjs from 'vite-plugin-commonjs'
import {
    defineConfig
} from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        uni(),
        commonjs(),
        // Components({
        //     resolvers: [VantResolver()],
        // }),
    ],
    css: {
        preprocessorOptions: {
            scss: {
                api: 'modern-compiler' // 使用新的现代编译器API，避免旧版JS API弃用警告
            }
        }
    },
    resolve: {
        alias: {
            '@vue/shared': '@vue/shared/dist/shared.esm-bundler.js',
			'@': 'src',
			'jweixin-module': path.resolve(__dirname, 'src/js_sdk/jweixin-module/index.js')
        }
    },
    optimizeDeps: {
        entries: [
            'src/main.js',
            'src/App.vue',
            'src/pages/**/*.vue'
        ],
        include: [
            'tim-wx-sdk',
            'tim-js-sdk',
            'trtc-js-sdk',
            'cos-wx-sdk-v5',
            'jweixin-module'
        ]
    },
    build: {
        chunkSizeWarningLimit: 1000,
        rollupOptions: {
            output: {
                manualChunks(id) {
                    if (!id.includes('node_modules')) return;
                    if (/[\\/]node_modules[\\/](tim-|trtc-|cos-|webrtc-adapter)/.test(id)) {
                        return 'vendor-tencent';
                    }
                    if (/[\\/]node_modules[\\/](@vant|weui-miniprogram|vant-aliapp)/.test(id)) {
                        return 'vendor-ui';
                    }
                    if (/[\\/]node_modules[\\/](@dcloudio|vue|vuex|vue-router)/.test(id)) {
                        return 'vendor-core';
                    }
                }
            }
        }
    },
	server: {
	    host: '0.0.0.0',
        warmup: {
            clientFiles: [
                'src/main.js',
                'src/App.vue',
                'src/**/*.vue'
            ]
        },
	    allowedHosts: [
	      'frp.12123wzcx.com' // 允许所有 frp.12123wzcx.com 的子域名
	    ],
	    proxy: {
			'/bdhealth': {
				target: 'https://hlwyy.scsmysgkyy.cn',
				changeOrigin: true,
				rewrite: (path) => path.replace('/bdhealth', '/bdhealth')
			},
			'/openID': {
				target: 'https://hlwyy.scsmysgkyy.cn',
				changeOrigin: true,
				rewrite: (path) => path.replace('/openID', '/openID')
			},
			'/images': {
				target: 'https://hlwyy.scsmysgkyy.cn',
				changeOrigin: true,
				rewrite: (path) => path.replace('/images', '/images')
			},
			// '/MP_verify_mRdA5h8p5Phywrus.txt': {
			// 	target: 'http://localhost:81',
			// 	changeOrigin: true,
			// 	rewrite: (path) => path.replace('/MP_verify_mRdA5h8p5Phywrus.txt', '/MP_verify_mRdA5h8p5Phywrus.txt')
			// },
			'/ws/': {
				target: 'https://apis.map.qq.com',
				changeOrigin: true,
				rewrite: (path) => path.replace('/ws/', '/ws/')
			},
			'/EMRFile': {
				target: 'https://hlwyy.scsmysgkyy.cn',
				changeOrigin: true,
			},
			'/fileUp/': {
				target: 'https://np.h03.p0551.com',
				changeOrigin: true,
				rewrite: (path) => path.replace('/fileUp/', '')
			},
			'/pingd': {
				target: 'https://pingtas.qq.com',
				changeOrigin: true,
			},
            '/patientapp/images': {
				target: 'https://hlwyy.scsmysgkyy.cn',
				changeOrigin: true,
				rewrite: (path) => path.replace('/patientapp/images', '/images')
			},
			'/uploadFile': {
				target: 'https://hlwyy.scsmysgkyy.cn',
				changeOrigin: true,
				rewrite: (path) => path.replace('/uploadFile', '/uploadFile')
			},

	    }
	},
})
