jiangping
2025-06-09 663dbe4ddca1fa409e6acbc1f77d924c161b0c39
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
// 详细配置请参考https://cli.vuejs.org/zh/config/#vue-config-js
// const outputDir = process.env.VUE_APP_CONTEXT_PATH.substring(1, process.env.VUE_APP_CONTEXT_PATH.length - 1)
// const outputDir = process.env.VUE_APP_CONTEXT_PATH.substring(1, process.env.VUE_APP_CONTEXT_PATH.length)
const CompressionPlugin = require('compression-webpack-plugin')
module.exports = {
  publicPath: './',
  outputDir: process.env.VUE_APP_CONTEXT_NAME,
  assetsDir: 'static',
  lintOnSave: false,
  devServer: {
    host: '0.0.0.0',
    port: 10086,
    proxy: {
      [process.env.VUE_APP_API_PREFIX]: {
        target: process.env.VUE_APP_API,
        changeOrigin: true,
        pathRewrite: {
          [`^${[process.env.VUE_APP_API_PREFIX]}`]: ''
        }
      }
    }
  },
  configureWebpack: config => {
    // if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'test') {
    return {
      plugins: [
        new CompressionPlugin({
          algorithm: 'gzip', // 使用gzip压缩
          test: /\.(js|css|html)$/, // 匹配文件类型
          threshold: 10240, // 只处理比这个值大的资源。值是字节,10240字节=10KB
          minRatio: 0.8 // 压缩比率,只有压缩率小于这个值的资源才会被处理
        })
      ],
      optimization: {
        runtimeChunk: 'single',
        splitChunks: {
          chunks: 'all',
          maxInitialRequests: Infinity,
          minSize: 20000,
          cacheGroups: {
            vendors: {
              test: /[\\/]node_modules[\\/]/, // 使用正则匹配node_modules中引入的模块
              priority: -10, // 优先级值越大优先级越高,默认-10,不用修改
              name(module) {
                // 设定分包以后的文件模块名字,按照包名字替换拼接一下
 
                if (!module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)) return;
                const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
                return `npm.${packageName.replace('@', '')}`;
              }
            }
          }
        }
      }
    }
    // }
  }
}