const { defineConfig } = require('@vue/cli-service');

module.exports = defineConfig({
  transpileDependencies: true,
  
  // 生产环境不生成source map
  productionSourceMap: false,
  
  // 开发环境：关闭浏览器全屏遮罩错误提示，仅在控制台输出
  // 说明：webpack-dev-server v4 推荐使用 client.overlay=false
  // 如果未来降级到 v3，可改为 overlay:false
  devServer: {
    client: {
      overlay: false
    }
    // overlay: false
  },
  
  configureWebpack: {
    optimization: {
      splitChunks: {
        chunks: 'all',
        minSize: 100000,    // 增加最小分块大小到100KB
        maxSize: 500000,    // 增加最大分块大小到500KB
        cacheGroups: {
          vendors: {
            name: 'chunk-vendors',
            test: /[\\/]node_modules[\\/]/,
            priority: -10,
            chunks: 'initial'
          },
          common: {
            name: 'chunk-common',
            minChunks: 2,
            priority: -20,
            chunks: 'initial',
            reuseExistingChunk: true
          }
        }
      }
    }
  },

  chainWebpack: config => {
    // 移除 prefetch 插件，减少不必要的预加载
    config.plugins.delete('prefetch');
    
    // 简化HTML压缩
    config.plugin('html').tap(args => {
      args[0].minify = {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true
      };
      return args;
    });
  },
  
  css: {
    extract: true,
    sourceMap: false
  }
});