浏览代码

IE兼容,完整

zhengnaiwen_citu 2 月之前
父节点
当前提交
749ec487ca
共有 6 个文件被更改,包括 553 次插入620 次删除
  1. 1 8
      .browserslistrc
  2. 7 9
      babel.config.js
  3. 503 497
      package-lock.json
  4. 2 4
      package.json
  5. 6 7
      src/main.js
  6. 34 95
      vue.config.js

+ 1 - 8
.browserslistrc

@@ -1,11 +1,4 @@
-# 支持 IE11 的生产环境配置
 > 1%
 last 2 versions
-not dead
 ie >= 11
-
-# 开发环境配置
-[development]
-last 1 chrome version
-last 1 firefox version
-last 1 safari version
+not dead

+ 7 - 9
babel.config.js

@@ -8,16 +8,14 @@ if (process.env.NODE_ENV === 'production') {
 
 module.exports = {
   presets: [
-    [
-      '@vue/cli-plugin-babel/preset',
-      {
-        useBuiltIns: 'entry', // 推荐使用 'entry' 而非 'usage' 确保完全覆盖
-        corejs: 3, // 使用 core-js@3 版本
-        targets: {
-          ie: '11' // 明确指定 IE11 为目标
-        }
+    '@vue/cli-plugin-babel/preset',
+    ['@babel/preset-env', {
+      useBuiltIns: 'usage', // 按需引入polyfill
+      corejs: 3, // 指定core-js版本
+      targets: {
+        ie: '11' // 目标环境
       }
-    ]
+    }]
   ],
   plugins
 }

文件差异内容过多而无法显示
+ 503 - 497
package-lock.json


+ 2 - 4
package.json

@@ -12,11 +12,10 @@
     "@babel/plugin-transform-runtime": "^7.24.6",
     "@babel/preset-env": "^7.23.9",
     "@mdi/font": "^7.4.47",
-    "@vue/composition-api": "^1.7.2",
     "@wangeditor/editor": "^5.1.23",
     "@wangeditor/editor-for-vue": "^1.0.2",
     "axios": "^1.7.2",
-    "core-js": "^3.8.3",
+    "core-js": "^3.44.0",
     "decimal.js": "^10.5.0",
     "echarts": "^5.6.0",
     "element-resize-detector": "^1.2.4",
@@ -24,7 +23,7 @@
     "fs": "0.0.1-security",
     "lodash": "^4.17.21",
     "nprogress": "^0.2.0",
-    "qs": "^6.14.0",
+    "qs": "^6.10.4",
     "regenerator-runtime": "^0.14.1",
     "relation-graph": "^2.2.11",
     "scrolling-element": "^1.0.2",
@@ -62,7 +61,6 @@
     "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"
   }
 }

+ 6 - 7
src/main.js

@@ -1,10 +1,11 @@
+
 import 'core-js/stable'
 import 'regenerator-runtime/runtime'
 import 'whatwg-fetch' // fetch ie 11
-import 'es6-promise/auto' // Promise polyfill
+// import 'es6-promise/auto' // Promise polyfill
 import 'scrolling-element'
-// import promise from 'es6-promise'
-import VueCompositionAPI from '@vue/composition-api'
+import promise from 'es6-promise'
+// import VueCompositionAPI from '@vue/composition-api'
 import Vue from 'vue'
 import App from './App.vue'
 import router from './router'
@@ -20,8 +21,7 @@ import '@mdi/font/css/materialdesignicons.min.css'
 import '@/styles/index.scss'
 import '@/styles/orangeTheme.scss'
 
-// require('@babel/polyfill')
-// promise.polyfill()
+promise.polyfill()
 
 // 修改 MessageBox 的默认配置
 ElementUI.MessageBox.setDefaults({
@@ -30,10 +30,9 @@ ElementUI.MessageBox.setDefaults({
   type: 'warning',
   confirmButtonClass: 'el-button--orange'
 })
-
 Vue.use(ElementUI)
 Vue.use(Directives)
-Vue.use(VueCompositionAPI)
+// Vue.use(VueCompositionAPI)
 
 Vue.prototype.$DEFAULT_TITLE = '薪酬通'
 

+ 34 - 95
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()
@@ -11,6 +11,7 @@ module.exports = defineConfig({
   assetsDir: 'static',
   // 项目打包是否生成js的 source map 调试包,默认 true,生产部署设置为false
   productionSourceMap: process.env.NODE_ENV !== 'production',
+  // productionSourceMap: false,
   // devServer 支持 webpack-dev-server 所有选项
   devServer: {
     open: true,
@@ -64,34 +65,26 @@ module.exports = defineConfig({
   configureWebpack: config => {
     config.devtool = 'source-map'
     // 代码拆分
-    // config.optimization.splitChunks.chunks = 'all'
+    config.optimization.splitChunks.chunks = 'all'
+    config.entry = ['core-js/stable', 'regenerator-runtime/runtime', './src/main.js']
     // 代码拆分配置
-    config.optimization.splitChunks = {
-      chunks: 'all',
-      cacheGroups: {
-        vendors: {
-          test: /[\\/]node_modules[\\/]/,
-          priority: -10,
-          name: 'vendors'
-        },
-        common: {
-          minChunks: 2,
-          priority: -20,
-          reuseExistingChunk: true
-        }
-      }
-    }
+    // 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`
-    // 确保 polyfill 最先加载
-    config.entry = {
-      app: [
-        'core-js/stable',
-        'regenerator-runtime/runtime',
-        'whatwg-fetch', // 添加 fetch polyfill
-        './src/main.js'
-      ]
-    }
 
     config.module.rules.push(
       {
@@ -108,76 +101,22 @@ 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') {
-      const TerserPlugin = require('terser-webpack-plugin')
-      config.optimization.minimizer = [
-        new TerserPlugin({
-          parallel: true,
-          terserOptions: {
-            ecma: 5, // 指定为 ES5
+      config.plugins.push(
+        new UglifyJsPlugin({
+          uglifyOptions: {
             compress: {
               drop_console: true,
-              drop_debugger: true,
-              pure_funcs: ['console.log'] // 移除特定的 console 方法
+              drop_debugger: true
             },
             output: {
-              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
-      //   }))
+              comments: false
+            }
+          },
+          sourceMap: false,
+          parallel: true
+        }))
     }
   },
   chainWebpack: config => {
@@ -198,25 +137,24 @@ module.exports = defineConfig({
     // 'vue',
     // 'vuex',
     // 'vue-router',
-    '@vue/composition-api',
 
     // UI 组件库
     'element-ui',
+    // 'async-validator',
 
     // 编辑器
     '@wangeditor/editor',
     '@wangeditor/editor-for-vue',
 
-    '@mdi/font',
+    // '@mdi/font',
 
-    'scrolling-element',
+    // 'scrolling-element',
 
     // // 其他可能包含 ES6 代码的依赖
     'fs',
-    'qs',
     'axios',
     'lodash',
-    'echarts',
+    // 移除 'echarts' 以避免模块转换问题
     'decimal.js',
     'nprogress',
     'element-resize-detector',
@@ -225,6 +163,7 @@ module.exports = defineConfig({
     /node_modules\/@wangeditor/
     // /node_modules\/vue-/,
     // /node_modules\/element-ui/,
+    // 注释掉 echarts 相关的转译配置
     // /node_modules\/echarts/
   ],
   // 移除console

部分文件因为文件数量过多而无法显示