import {defineConfig} from 'vite'
import legacy from '@vitejs/plugin-legacy'
import vue from '@vitejs/plugin-vue'
import {resolve} from 'path'
// vue setup 的糖语法
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
// 不用导入 vue 的 import 了
import AutoImport from 'unplugin-auto-import/vite'
import Icons from "unplugin-icons/vite";

const pathResolve = (dir) => {
    return resolve(__dirname, '.', dir)
}

const alias = {
    '@': pathResolve('src'),
}

export default defineConfig({
    esbuild: {
        jsxFactory: 'h',
        jsxFragment: 'Fragment'
    },
    externals: {
        "BMap": "BMap",
        "BMapLib": "BMapLib"
    },
    resolve: {
        alias,
        extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
    },
    plugins: [
        Icons({
            autoInstall: true,
            compiler: "vue3",
        }),
        VueSetupExtend(),
        vue({
            refTransform: true
        }),
        legacy({
            targets: 'chrome 49',
        }),
        AutoImport({
            dts: 'src/auto-imports.d.ts',
            imports: ['vue']
        })
    ],
    server: {
        host: '0.0.0.0',
        port: 3000,
        proxy: {
            '/emr/runtime': {
                //这里配置运行时服务地址
                target: 'http://172.16.32.125:8001/emr',
                secure: false, //如果运行时服务是https，此处配置为true
                changeOrigin: true, //支持跨域调用，这里配置为true
                rewrite: path => path.replace(/^\/emr/, '')
            },
            '/emr/archive': {
                //这里配置运行时服务地址
                target: 'http://172.16.32.125:8001/emr',
                secure: false, //如果运行时服务是https，此处配置为true
                changeOrigin: true, //支持跨域调用，这里配置为true
                rewrite: path => path.replace(/^\/emr/, '')
            },
            '/bdp/dataservice/api': {
                // 这个地址是，创智和宇的查询电子病历下拉框的接口
                target: 'http://172.16.32.183:8888',
                secure: false,
                changeOrigin: true
            },
        }
    },
    build: {
        chunkSizeWarningLimit: 1000,
    },
})
