Explorar el Código

build: optimize webpack production configuration

- Add mode: 'production' to enable webpack defaults
- Add performance hints configuration with adjusted thresholds
  - maxAssetSize: 1MB (for images)
  - maxEntrypointSize: 2MB (for bundles)
  - Only warn for .js and .css files
- Add commons chunk group for better code splitting
- Enable console removal in production (drop_console, drop_debugger)
- Add CSS and JS minification in HtmlWebpackPlugin

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Ryuiso hace 3 semanas
padre
commit
cb38bc3fad
Se han modificado 1 ficheros con 32 adiciones y 10 borrados
  1. 32 10
      build/webpack.prod.conf.js

+ 32 - 10
build/webpack.prod.conf.js

@@ -14,6 +14,7 @@ const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
 const env = require('../config/prod.env')
 
 const webpackConfig = merge(baseWebpackConfig, {
+  mode: 'production',
   module: {
     rules: utils.styleLoaders({
       sourceMap: config.build.productionSourceMap,
@@ -42,26 +43,45 @@ const webpackConfig = merge(baseWebpackConfig, {
           test: /[\\/]src[\\/]/,
           priority: -20,
           chunks: 'initial'
+        },
+        commons: {
+          name: 'commons',
+          minChunks: 2,
+          priority: -30,
+          chunks: 'initial',
+          reuseExistingChunk: true
         }
       }
     },
     runtimeChunk: {
       name: 'manifest'
+    },
+    minimizer: [
+      new UglifyJsPlugin({
+        uglifyOptions: {
+          compress: {
+            warnings: false,
+            drop_console: true,
+            drop_debugger: true
+          }
+        },
+        sourceMap: config.build.productionSourceMap,
+        parallel: true
+      })
+    ]
+  },
+  performance: {
+    hints: 'warning',
+    maxAssetSize: 1024000,
+    maxEntrypointSize: 2048000,
+    assetFilter: function (assetFilename) {
+      return assetFilename.endsWith('.js') || assetFilename.endsWith('.css')
     }
   },
   plugins: [
     new webpack.DefinePlugin({
       'process.env': env
     }),
-    new UglifyJsPlugin({
-      uglifyOptions: {
-        compress: {
-          warnings: false
-        }
-      },
-      sourceMap: config.build.productionSourceMap,
-      parallel: true
-    }),
     new ExtractTextPlugin({
       filename: utils.assetsPath('css/[name].[hash].css'),
       allChunks: true,
@@ -78,7 +98,9 @@ const webpackConfig = merge(baseWebpackConfig, {
       minify: {
         removeComments: true,
         collapseWhitespace: true,
-        removeAttributeQuotes: true
+        removeAttributeQuotes: true,
+        minifyCSS: true,
+        minifyJS: true
       },
       chunksSortMode: 'auto'
     }),