|
@@ -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 => {
|