import { defineConfig, loadEnv } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import path from "path";



// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {

  return {
    base: "./", //等同於  assetsPublicPath :'./'
    plugins: [uni(),
      { // 自定义插件禁用vite:vue插件的devToolsEnabled，强制编译 vue 模板时 inline 为 true
        name: 'fix-vite-plugin-vue',
        configResolved(config) {
            const plugin = config.plugins.find((p) => p.name === 'vite:vue')
            if (plugin && plugin.api && plugin.api.options) {
                plugin.api.options.devToolsEnabled = false
            }
        },
    },
    ],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src/'),
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          preprocessorOptions: `@import "@/static/css/common.scss";`
        },
      }
    },
    server: {
      host: '0.0.0.0',
      port: 8081,
      https: false,
      proxy: {
        '/api': {
          target: loadEnv(mode, process.cwd()).VITE_APP_URL_H5,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    }
  }
});
