/*
 * @Author: YKH
 * @Date: 2021-12-08 10:26:27
 * @LastEditTime: 2021-12-19 10:26:10
 * @Description: 
 * @FilePath: \cool-admin\cool-admin-vue-vue3-ts-vite\vite.config.ts
 */
import path from "path";
import type { UserConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import { svgBuilder } from "./src/core/utils/svg";

function resolve(dir: string) {
	return path.resolve(__dirname, ".", dir);
}

// https://vitejs.dev/config/

export default (): UserConfig => {
	return {
		base: "/",
		plugins: [vue(), vueJsx(), svgBuilder("./src/icons/svg/")],
		resolve: {
			alias: {
				"/@": resolve("src"),
				"/#": resolve("types"),
				"/$": resolve("src/cool/modules")
			}
		},
		css: {
			preprocessorOptions: {
				scss: {
					additionalData: "@import './src/assets/css/common.scss';"
				}
			}
		},
		server: {
			port: 9000,
			host: '0.0.0.0',
			hmr: {
				overlay: true
			},
			proxy: {
				"/dev": {
					target: "http://127.0.0.1:8001",
					changeOrigin: true,
					rewrite: (path) => path.replace(/^\/dev/, "")
				},

				"/pro": {
					target: "http://ykhvip.fun",
					changeOrigin: true,
					rewrite: (path) => path.replace(/^\/pro/, "/api")
				}
			},
			// fs: {
			// 	strict: false
			// }
		},
		build: {
			sourcemap: false,
			polyfillDynamicImport: false // 必须为false
		},
		optimizeDeps: {
			exclude: ["vue-demi"]
		}
	};
};
