import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import mkcert from 'vite-plugin-mkcert'

// https://vitejs.dev/config/
export default defineConfig(() => {
  return {
    plugins: [react(), mkcert()],
    server: {
      open: true,
      host: 'dev.ezijing.com',
      proxy: {
        '/api/wenku': {
          target: 'https://wenchain.baidu.com',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api\/wenku/, '/'),
        },
        '/api': {
          target: 'https://zijingebook.ezijing.com',
          changeOrigin: true,
        },
      },
    },
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
    css: {
      preprocessorOptions: {
        less: {
          javascriptEnabled: true,
        },
      },
    },
  }
})
