// @ts-nocheck
import { defineConfig } from '@rspack/cli';
import { rspack } from '@rspack/core';
import { merge } from 'webpack-merge';
import { baseConfig } from './rspack.base.config';

export default defineConfig(
  merge(baseConfig, {
    mode: 'production',
    entry: {
      main: './src/main.ts',
    },
    devtool: false,
    output: {
      clean: true,
      filename: '[name].[contenthash].js',
      chunkFilename: '[name].[contenthash].js',
    },
    optimization: {
      minimize: true,
      minimizer: [
        new rspack.SwcJsMinimizerRspackPlugin(),
        new rspack.LightningCssMinimizerRspackPlugin(),
      ],
      splitChunks: {
        chunks: 'async',
        minChunks: 1,
        minSize: 2000,
        maxAsyncRequests: 30,
        maxInitialRequests: 30,
        cacheGroups: {
          'vue-router': {
            name: 'vue-router',
            test: /[\\/]node_modules[\\/]vue-router[\\/]/,
            priority: 120,
            chunks: 'all',
            reuseExistingChunk: true,
          },

          vue: {
            name: 'vue',
            test: /[\\/]node_modules[\\/]vue[\\/]/,
            priority: 200,
            chunks: 'all',
            reuseExistingChunk: true,
          },
          axios: {
            name: 'axios',
            test: /[\\/]node_modules[\\/]axios[\\/]/,
            priority: 9,
            chunks: 'all',
            reuseExistingChunk: true,
          },
          defaultVendors: {
            test: /[\\/]node_modules[\\/]/,
            priority: -10,
            reuseExistingChunk: true,
          },
          default: {
            minChunks: 2,
            priority: -20,
            reuseExistingChunk: true,
          },
        },
      },
    },
  }),
);
