Browse Source

大文件拆分
Signed-off-by: caner <5658514@qq.com>

caner 3 years ago
parent
commit
7597094168
1 changed files with 21 additions and 1 deletions
  1. 21 1
      vue.config.js

+ 21 - 1
vue.config.js

@@ -20,7 +20,27 @@ module.exports = {
                         threshold: 10240, // 对超过10k的文件进行压缩
                         deleteOriginalAssets: false // 是否删除原文件                        
                     })
-                ]
+                ],
+                optimization: {
+                    runtimeChunk: 'single',
+                    splitChunks: {
+                        chunks: 'all',
+                        maxInitialRequests: Infinity,
+                        minSize: 20000,
+                        cacheGroups: {
+                            vendor: {
+                                test: /[\\/]node_modules[\\/]/,
+                                name(module) {
+                                    // get the name. E.g. node_modules/packageName/not/this/part.js
+                                    // or node_modules/packageName
+                                    const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
+                                    // npm package names are URL-safe, but some servers don't like @ symbols
+                                    return `npm.${packageName.replace('@', '')}`
+                                }
+                            }
+                        }
+                    }
+                }
             }
         }
     }