import baseConfig from './vite.config.base.mts';
import configCompressPlugin from './plugin/compress';
import configVisualizerPlugin from './plugin/visualizer';
import configArcoResolverPlugin from './plugin/arcoResolver';
import configImageminPlugin from './plugin/imagemin';
import type { UserConfigExport, ConfigEnv } from 'vite';

export default ({ mode }: ConfigEnv): UserConfigExport => {
  return {
    mode: 'production',
    plugins: [
      configCompressPlugin('gzip'),
      configVisualizerPlugin(),
      configArcoResolverPlugin(),
      configImageminPlugin()
    ],
    build: {
      // 浏览器兼容目标
      target: 'es2015',
      // 是否生成 source map 文件
      sourcemap: false,
      rollupOptions: {
        output: {
          entryFileNames: 'static/js/[name]-[hash].js',
          chunkFileNames: 'static/js/[name]-[hash].js',
          assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
          manualChunks: {
            arco: ['@arco-design/web-vue'],
            chart: ['echarts', 'vue-echarts'],
            vue: ['vue', 'vue-router', 'pinia', '@vueuse/core']
          }
        }
      },
      chunkSizeWarningLimit: 2000
    },
    ...baseConfig({ mode } as ConfigEnv)
  };
};
