import { mergeConfig } from 'vite';
import baseConfig from './vite.config.base';
import configCompressPlugin from './plugin/compress';
import configVisualizerPlugin from './plugin/visualizer';
import configArcoResolverPlugin from './plugin/arcoResolver';
import configImageminPlugin from './plugin/imagemin';

export default mergeConfig(
  {
    mode: 'production',
    plugins: [
      configCompressPlugin('gzip'),
      configVisualizerPlugin(),
      configArcoResolverPlugin(),
      configImageminPlugin(),
    ],
    build: {
      rollupOptions: {
        output: {
          // 修改代码分割策略，将 arco 与 vue 合并到一个 chunk 中
          manualChunks: {
            // arco: ['@arco-design/web-vue'], // 暂时移除单独的 arco 分包
            vue: [
              'vue',
              'vue-router',
              'pinia',
              '@vueuse/core',
              'vue-i18n',
              '@arco-design/web-vue',
            ],
          },
        },
      },
      chunkSizeWarningLimit: 2000,
    },
  },
  baseConfig
);
