import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { createHtmlPlugin } from "vite-plugin-html";
import tester from "@rollup/plugin-terser";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    createHtmlPlugin({
      minify: true,
    }),
  ],
  base: "./",
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },
  resolve: {
    alias: {
      "@": "/src",
    },
  },
  build: {
    minify: true,
    rollupOptions: {
      input: "index.html",
      output: {
        manualChunks: {
          react: ["react", "react-dom"],
          vendors: ["@loadable/component"],
        },
      },
      plugins: [
        tester({
          format: {
            comments: false, // 移除注释
          },
          compress: {
            drop_console: true, // 删除 console 函数
            drop_debugger: true, // 删除 debugger 语句
          },
          mangle: true, // 混淆变量名
        }),
      ],
    },
  },
});
