Просмотр исходного кода

fix: chainWebpack根据环境区分修改、加载配置

lanjianrong 5 лет назад
Родитель
Сommit
2a6c124070
1 измененных файлов с 31 добавлено и 30 удалено
  1. 31 30
      config/config.js

+ 31 - 30
config/config.js

@@ -67,40 +67,41 @@ export default defineConfig({
       }
     ]
   ],
-  chainWebpack(config, { env }) {
+  chainWebpack(config) {
     config.plugin('windicss').use(windicss)
-    config.merge({
-      optimization: {
-        minimize: true,
-        splitChunks: {
-          chunks: 'async',
-          minSize: 30000,
-          minChunks: 2,
-          automaticNameDelimiter: '.',
-          cacheGroups: {
-            vendor: {
-              name: 'vendors',
-              test: /^.*node_modules[\\/](!lodash|antd).*$/,
-              chunks: 'all',
-              priority: 10
-            },
-            antd: {
-              name: 'antd',
-              test: /[\\/]node_modules[\\/]antd[\\/]/,
-              chunks: 'all',
-              priority: 9
-            },
-            lodash: {
-              name: 'lodash',
-              test: /[\\/]node_modules[\\/]lodash[\\/]/,
-              chunks: 'all',
-              priority: -2
+
+    if (REACT_APP_ENV === 'prod') {
+      config.merge({
+        optimization: {
+          minimize: true,
+          splitChunks: {
+            chunks: 'async',
+            minSize: 30000,
+            minChunks: 2,
+            automaticNameDelimiter: '.',
+            cacheGroups: {
+              vendor: {
+                name: 'vendors',
+                test: /^.*node_modules[\\/](!lodash|antd).*$/,
+                chunks: 'all',
+                priority: 10
+              },
+              antd: {
+                name: 'antd',
+                test: /[\\/]node_modules[\\/]antd[\\/]/,
+                chunks: 'all',
+                priority: 9
+              },
+              lodash: {
+                name: 'lodash',
+                test: /[\\/]node_modules[\\/]lodash[\\/]/,
+                chunks: 'all',
+                priority: -2
+              }
             }
           }
         }
-      }
-    })
-    if (env === 'production') {
+      })
       config.plugin('compression-webpack-plugin').use(
         new CompressionWebpackPlugin({
           // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称