import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import eslintPlugin from '@nabla/vite-plugin-eslint'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  return {
    base: mode === 'production' ? '/' : '/',
    server: {
      host: '0.0.0.0',
      port: 9528,
      proxy: {
        '/api': {
          target: 'http://zohocrm.promocollection.com.au:9007/',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ''),
        },
        '/bpi': {
          // target: 'http://api.promocollection.com.cn:9004',
          target: 'http://192.168.10.62:8099',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/bpi/, ''),
        },
      },
    },
    resolve: {
      alias: {
        '@': '/src/',
      },
    },
    css: {
      devSourcemap: true,
      preprocessorOptions: {
        scss: {
          api: 'modern',
          additionalData: `@use '@/assets/css/var.scss' as *;`,
        },
      },
    },
    plugins: [
      vue({ template: { compilerOptions: { hoistStatic: false } } }),
      eslintPlugin(),
    ],
    build: {
      // 设置最终构建的浏览器兼容目标
      target: 'es2020',
      // 构建后是否生成 source map 文件
      sourcemap: false,
      // chunk 大小警告的限制(以 kbs 为单位)
      chunkSizeWarningLimit: 1000,
      // 启用/禁用 gzip 压缩大小报告
      reportCompressedSize: false,
    },
  }
})