广州市综治平台前端
xusd
2 days ago b4725b231cfe2a710288e8bd0b1b9d990989f90c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * @Company: hugeInfo
 * @Author: ldh
 * @Date: 2022-02-18 14:58:23
 * @LastEditTime: 2024-12-20 10:49:29
 * @LastEditors: lwh
 * @Version: 1.0.0
 * @Description: less配置
 */
const CracoLessPlugin = require('craco-less');
const path = require('path');
 
module.exports = {
    optimization: {
        // 配置代码分割(splitChunks)策略,以优化打包后的文件大小和加载性能
        splitChunks: {
            chunks: 'all', // 对所有类型的块进行分割
            minSize: 20000, // 最小的块大小为 20KB
            maxSize: 0, // 不设置最大块大小,让 Webpack 自动决定
            minChunks: 1, // 至少有 1 个模块共享时才进行分割
            maxAsyncRequests: 30, // 异步加载时的最大请求数量
            maxInitialRequests: 3, // 初始加载时的最大请求数量
            automaticNameDelimiter: '~', // 使用波浪线 (~) 作为分隔符
            enforceSizeThreshold: 50000, // 强制分割的阈值
            cacheGroups: {
                vendors: {
                    test: /[\\/]node_modules[\\/]/, // 匹配 node_modules 中的模块
                    priority: -10, // 优先级较低
                    reuseExistingChunk: true, // 如果已存在的 chunk 可以满足条件,则重用它
                },
                defaultVendors: {
                    test: /[\\/]node_modules[\\/]/, // 匹配 node_modules 中的模块
                    priority: -20, // 更低的优先级
                    reuseExistingChunk: true, // 如果已存在的 chunk 可以满足条件,则重用它
                    filename: 'vendors.[contenthash:8].js', // 生成的文件名
                },
                default: {
                    minChunks: 2, // 至少有 2 个模块共享时才进行分割
                    priority: -20, // 较低的优先级
                    reuseExistingChunk: true, // 如果已存在的 chunk 可以满足条件,则重用它
                    filename: 'common.[contenthash:8].js', // 生成的文件名
                },
            },
        },
    },
    plugins: [
        {
            plugin: CracoLessPlugin,
            options: {
                lessLoaderOptions: {
                    lessOptions: {
                        javascriptEnabled: true,
                    },
                },
            },
        },
    ],
    webpack: {
        alias: {
            '@': path.resolve(__dirname, 'src'),
        },
    },
};