1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const path = require('path')
// js压缩插件
const TerserPlugin = require("terser-webpack-plugin")
// 设置moment
const MomentLocalesPlugin = require('moment-locales-webpack-plugin')
const CompressionPlugin = require("compression-webpack-plugin")
const isRrod = process.env.NODE_ENV === 'prod';
const date = new Date();
const Version = '' + date.getFullYear() + (date.getMonth() + 1) + date.getDate() + date.getHours();
function resolve (dir) {
// path.join()方法用于连接路径
return path.join(__dirname, dir)
}
module.exports = {
runtimeCompiler: true,
indexPath: "index.html",
publicPath: '/', // 设置打包文件相对路径
outputDir: 'dist',
/* configureWebpack: {
//关闭 webpack 的性能提示
performance: {
hints: false
},
output: { // 输出重构 打包编译后的 文件名称 【版本号】
filename: `js/[name].${Version}.js`,
chunkFilename: `js/[name].${Version}.js`,
}
},*/
// productionSourceMap: isRrod ? false : true,
productionSourceMap: false,
// devServer: {
// port: 8089,
// open: true,
// proxy: { //配置跨域
// '/api': {
// target: 'http://123.56.183.13:8889', //真实的后台接口
// changOrigin: true, //允许跨域
// pathRewrite: {
// /* 重写路径,当我们在浏览器中看到请求的地址为:http://localhost:8080/api/core/getData/userInfo 时
// 实际上访问的地址是:http://121.121.67.254:8185/core/getData/userInfo,因为重写了 /api
// */
// '^/api': ''
// }
// },
// '/checkApi': {
// target: 'https://beta-yac.yiboshi.com', //真实的后台接口
// changOrigin: true, //允许跨域
// pathRewrite: {
// '^/checkApi': ''
// }
// },
// }
// },
devServer: {
open: true,
overlay: {
warning: false,
errors: false
},
https:true,
},
chainWebpack: (config) => {
config.plugins.delete('preload')
// 移除 prefetch 插件
config.plugins.delete('prefetch')
// ant图标按需引入
// config.resolve.alias.set('@ant-design/icons/lib/dist$', resolve("src/views/utils/icons.js"))
if (process.env.NODE_ENV === 'production') {
config.plugin('extract-css').tap(args => {
args[0].filename = `css/[name].[contenthash:8].css`
return args
})
}
},
configureWebpack: config => {
// 开启gzip压缩
/*if (process.env.NODE_ENV === 'production') {*/
config.plugins.push(
new CompressionPlugin({
filename: '[path][base].gz',
test: /\.js$|\.html$|\.css/, // 匹配文件名
threshold: 10,
})
)
/* }*/
config.externals = {
'html2canvas': 'html2canvas'
}
// 输出重构 打包编译后的 文件名称 【版本号】
config.output.filename = `js/[name].${Version}.js`
config.output.chunkFilename = `js/[name].${Version}.js`
// 剥离除 “en” 以外的所有语言环境
config.plugins.push(new MomentLocalesPlugin())
// 压缩js
config.optimization.minimizer.push(
new TerserPlugin({
// 启用多线程
parallel: 4,
terserOptions: {
format: {
comments: false
},
compress: {
drop_console: true,
drop_debugger: false,
pure_funcs: ['console.log'], // 移除console
},
// 删除注释
extractComments: false
}
})
)
},
css: {
loaderOptions: {
less: {
modifyVars: {
'primary-color': '#FF4D80',
'border-primary-color': '#FFB4C0',
'border-radius-base': '2px',
},
javascriptEnabled: true
}
}
},
}