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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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 VueLoaderPlugin = require('vue-loader/lib/plugin');
// module.exports = {
// entry:path.join(__dirname,'./src/main.js'),
// output:{
// path:path.join(__dirname,'./dist'),
// filename:'bundle.js'
// },
// module:{
// rules: [
// {
// test:/\.vue$/,
// loader: 'vue-loader',
// },
// {// 添加这个json,解决如上的报错问题
// test: /\.scss$/,
// use: ['style-loader','css-loader', 'sass-loader']
// },
// ]
// },
// plugins: [
// new VueLoaderPlugin()
// ]
// }
const isRrod = process.env.NODE_ENV === 'dev';
const date = new Date();
const Version = date.getTime();
const port = 8081;
// 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: port,
open: true,
overlay: {
warning: false,
errors: false
},
// lintOnSave: false,
// host: 'local.yiboshi.com',
https: false,
proxy: {
'/v1/science-admin': {
target: process.env.VUE_APP_BASE_URL, //真实的后台接口
changOrigin: true, //允许跨域
pathReWrite: {
'^/v1/science-admin': '/v1/science-admin'
}
},
'/upload/files': {
target: process.env.VUE_APP_BASE_URL, //真实的后台接口
changOrigin: true, //允许跨域
pathReWrite: {
'^/upload/files': '/upload/files'
}
},
'/oauth/token': {
target: process.env.VUE_APP_BASE_URL,
changeOrigin: true,
pathRewrite: {
'^/oauth/token': '/oauth/token'
}
},
'/v1/user': {
target: process.env.VUE_APP_BASE_API,
changeOrigin: true,
pathRewrite: {
'^/v1/user': '/v1/user'
}
},
'/v1/function': {
target: process.env.VUE_APP_BASE_API,
changeOrigin: true,
pathRewrite: {
'^/v1/function': '/v1/function'
}
}
}
},
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',
// 解决xlsx-style报错的问题
'./cptable': 'var cptable'
}
// 输出重构 打包编译后的 文件名称 【版本号】
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
},
// 删除注释
// @ts-ignore
extractComments: false
}
})
)
},
pluginOptions: {
'style-resources-loader': {
preProcessor: 'less',
patterns: [
resolve('static/antd/variable.less')
]
}
},
css: {
loaderOptions: {
less: {
modifyVars: {
'primary-color': '#1890ff',
'border-primary-color': '#1890ff',
'border-radius-base': '2px',
},
javascriptEnabled: true
}
}
},
}