import { fileURLToPath, URL } from "node:url";

import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import { defineConfig } from "vite";

import AutoImport from "unplugin-auto-import/vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
import Components from "unplugin-vue-components/vite";
import svgLoader from "vite-svg-loader";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    svgLoader(),
    AutoImport({
      include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/, /\.md$/],
      imports: ["vue", "pinia", "vue-router"],
      dirs: ['./src/api/art'],
      resolvers: [NaiveUiResolver()],

    }),
    Components({
      resolvers: [NaiveUiResolver()],
    }),
  ],
  esbuild: {
    pure: ['console.log'], // 删除 console.log
    drop: ['debugger'], // 删除 debugger
  },
  define: {
    __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true'
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  base: "/blog/",
  server:{
    host:'0.0.0.0',
    port: 8080,
  },
  css: {
    preprocessorOptions: {
      less: {
        additionalData: '@import "colorofchina/color.less";',
        modifyVars: {
          hack: `true; @import (reference) "${resolve("src/assets/style/index.less")}";`,
        },
        javascriptEnabled: true,
      },
    },
  },
  compilerOptions: {
    allowJs: true,
  },
});
