Ver código fonte

添加插件uglifyjs-webpack-plugin

Luolei 6 anos atrás
pai
commit
444fee9bea
3 arquivos alterados com 19 adições e 5 exclusões
  1. 1 0
      package.json
  2. 0 3
      src/html/index.html
  3. 18 2
      webpack.config.js

+ 1 - 0
package.json

@@ -23,6 +23,7 @@
     "less-loader": "^4.1.0",
     "mini-css-extract-plugin": "^0.6.0",
     "style-loader": "^0.23.1",
+    "uglifyjs-webpack-plugin": "^2.1.2",
     "webpack": "^4.31.0",
     "webpack-dev-middleware": "^3.6.2",
     "webpack-dev-server": "^3.3.1"

+ 0 - 3
src/html/index.html

@@ -5,9 +5,6 @@
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <meta http-equiv="X-UA-Compatible" content="ie=edge">
   <title><%= htmlWebpackPlugin.options.title %></title>
-  <!--[if lt IE 9]>
-    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
-  <![endif]-->
 </head>
 
 <body>

+ 18 - 2
webpack.config.js

@@ -2,6 +2,7 @@ const path = require('path');
 const HtmlWebpackPlugin = require('html-webpack-plugin');
 const CleanWebpackPlugin = require('clean-webpack-plugin') // 清空打包目录的插件
 const MiniCssExtractPlugin = require('mini-css-extract-plugin');
+const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
 const webpack = require('webpack');
 const proxyHost = "http://192.168.2.236:5050";
 
@@ -113,6 +114,21 @@ module.exports = {
     new CleanWebpackPlugin(),
   ],
   optimization: { //webpack4.x的最新优化配置项,用于提取公共代码
+    minimizer: [
+      new UglifyJsPlugin({
+        uglifyOptions: {
+          warnings: false,
+          parse: {},
+          compress: {},
+          mangle: true, // Note `mangle.properties` is `false` by default.
+          output: null,
+          toplevel: false,
+          nameCache: null,
+          ie8: true,
+          keep_fnames: false,
+        },
+      }),
+    ],
     splitChunks: {
       cacheGroups: {
         commons: {
@@ -126,7 +142,7 @@ module.exports = {
       }
     }
   },
-
+      
   module: {
     rules: [{// 多个loader是有顺序要求的,从右往左写,因为转换的时候是从右往左转换的
         test: /\.js$/,
@@ -180,5 +196,5 @@ module.exports = {
       '/api': proxyHost
     },
     hot: true
-  },
+  }
 }