import {defineConfig, loadEnv} from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import {visualizer} from "rollup-plugin-visualizer";
// import commonjs from '@rollup/plugin-commonjs';

// https://vitejs.dev/config/
export default defineConfig(({mode}) => {
  const isH5 = process.env.UNI_PLATFORM === 'h5';
  const env = loadEnv(mode, process.cwd())
  return {
    plugins: [
      // commonjs(),
      uni(),
      visualizer()
    ],
    server: isH5 ? {
      proxy: {
        '/aiot-api': {
          target: env.VITE_BASE_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/aiot-api/, '')
        }
      }
    } : {
      port: 5100,
      fs: {
        // Allow serving files from one level up to the project root
        allow: ['..']
      }
    }
  }
});
