zhengnaiwen_citu 3 kuukautta sitten
vanhempi
commit
d1600fdea6
3 muutettua tiedostoa jossa 98 lisäystä ja 20 poistoa
  1. 6 6
      package-lock.json
  2. 1 0
      package.json
  3. 91 14
      vue.config.js

+ 6 - 6
package-lock.json

@@ -9924,9 +9924,9 @@
       }
     },
     "terser-webpack-plugin": {
-      "version": "5.3.11",
-      "resolved": "https://registry.npmmirror.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.11.tgz",
-      "integrity": "sha512-RVCsMfuD0+cTt3EwX8hSl2Ks56EbFHWmhluwcqoPKtBnfjiT6olaq7PRIRfhyU8nnC2MrnDrBLfrD/RGE+cVXQ==",
+      "version": "5.3.14",
+      "resolved": "https://registry.npmmirror.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.14.tgz",
+      "integrity": "sha512-vkZjpUjb6OMS7dhV+tILUW6BhpDR7P2L/aQSAv+Uwk+m8KATX9EccViHTJR2qDtACKPIYndLGCyl3FMo+r2LMw==",
       "dev": true,
       "requires": {
         "@jridgewell/trace-mapping": "^0.3.25",
@@ -9964,9 +9964,9 @@
           "dev": true
         },
         "schema-utils": {
-          "version": "4.3.0",
-          "resolved": "https://registry.npmmirror.com/schema-utils/-/schema-utils-4.3.0.tgz",
-          "integrity": "sha512-Gf9qqc58SpCA/xdziiHz35F4GNIWYWZrEshUc/G/r5BnLph6xpKuLeoJoQuj5WfBIx/eQLf+hmVPYHaxJu7V2g==",
+          "version": "4.3.2",
+          "resolved": "https://registry.npmmirror.com/schema-utils/-/schema-utils-4.3.2.tgz",
+          "integrity": "sha512-Gn/JaSk/Mt9gYubxTtSn/QCV4em9mpAPiR1rqy/Ocu19u/G9J5WWdNoUT4SiV6mFC3y6cxyFcFwdzPM3FgxGAQ==",
           "dev": true,
           "requires": {
             "@types/json-schema": "^7.0.9",

+ 1 - 0
package.json

@@ -59,6 +59,7 @@
     "pug-plain-loader": "^1.1.0",
     "sass": "~1.32.0",
     "sass-loader": "^10.0.0",
+    "terser-webpack-plugin": "^5.3.14",
     "uglifyjs-webpack-plugin": "^2.2.0",
     "vue-cli-plugin-vuetify": "~2.5.8",
     "vue-template-compiler": "^2.6.14"

+ 91 - 14
vue.config.js

@@ -1,6 +1,6 @@
 'use strict'
 const { defineConfig } = require('@vue/cli-service')
-const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
+// const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
 // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
 // 配置编辑器
 const Timestamp = new Date().getTime()
@@ -64,10 +64,34 @@ module.exports = defineConfig({
   configureWebpack: config => {
     config.devtool = 'source-map'
     // 代码拆分
-    config.optimization.splitChunks.chunks = 'all'
+    // config.optimization.splitChunks.chunks = 'all'
+    // 代码拆分配置
+    config.optimization.splitChunks = {
+      chunks: 'all',
+      cacheGroups: {
+        vendors: {
+          test: /[\\/]node_modules[\\/]/,
+          priority: -10,
+          name: 'vendors'
+        },
+        common: {
+          minChunks: 2,
+          priority: -20,
+          reuseExistingChunk: true
+        }
+      }
+    }
     config.output.filename = `static/js/[name].${Timestamp}.js`
     config.output.chunkFilename = `static/js/[name].${Timestamp}.js`
-    config.entry = ['core-js/stable', 'regenerator-runtime/runtime', './src/main.js']
+    // 确保 polyfill 最先加载
+    config.entry = {
+      app: [
+        'core-js/stable',
+        'regenerator-runtime/runtime',
+        'whatwg-fetch', // 添加 fetch polyfill
+        './src/main.js'
+      ]
+    }
 
     config.module.rules.push(
       {
@@ -83,23 +107,76 @@ module.exports = defineConfig({
       {
         test: /\.pug$/,
         loader: 'pug-plain-loader'
+      },
+      // 确保所有 JS 文件都经过 Babel 转译
+      {
+        test: /\.js$/,
+        include: [
+          // 特别包含可能有问题的 node_modules
+          /node_modules\/element-ui/,
+          /node_modules\/vue/,
+          /node_modules\/axios/,
+          /node_modules\/@wangeditor/
+        ],
+        use: {
+          loader: 'babel-loader',
+          options: {
+            presets: [
+              ['@babel/preset-env', {
+                targets: { ie: '11' },
+                useBuiltIns: 'usage',
+                corejs: 3
+              }]
+            ]
+          }
+        }
       })
     if (process.env.NODE_ENV === 'production') {
-      // 压缩 JS 文件
-      config.plugins.push(
-        new UglifyJsPlugin({
-          uglifyOptions: {
+      const TerserPlugin = require('terser-webpack-plugin')
+      config.optimization.minimizer = [
+        new TerserPlugin({
+          parallel: true,
+          terserOptions: {
+            ecma: 5, // 指定为 ES5
             compress: {
               drop_console: true,
-              drop_debugger: true
+              drop_debugger: true,
+              pure_funcs: ['console.log'] // 移除特定的 console 方法
             },
             output: {
-              comments: false // 移除注释
-            }
-          },
-          sourceMap: false,
-          parallel: true
-        }))
+              comments: false,
+              beautify: false,
+              // 确保不生成 ES6+ 语法
+              ecma: 5
+            },
+            // 特别针对 IE11 的兼容性设置
+            ie8: true
+          }
+        })
+      ]
+
+      // 添加 ES5 输出的额外配置
+      // config.output.environment = {
+      //   arrowFunction: false, // 不生成箭头函数
+      //   const: false,         // 不生成 const
+      //   destructuring: false, // 不生成解构赋值
+      //   forOf: false          // 不生成 for...of
+      // }
+      // // 压缩 JS 文件
+      // config.plugins.push(
+      //   new UglifyJsPlugin({
+      //     uglifyOptions: {
+      //       compress: {
+      //         drop_console: true,
+      //         drop_debugger: true
+      //       },
+      //       output: {
+      //         comments: false // 移除注释
+      //       }
+      //     },
+      //     sourceMap: false,
+      //     parallel: true
+      //   }))
     }
   },
   chainWebpack: config => {