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