forked from buqiyuan/vue3-antdv-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
190 lines (181 loc) · 5.82 KB
/
vue.config.js
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
185
186
187
188
189
190
const { defineConfig } = require('@vue/cli-service');
const webpack = require('webpack');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
// const CompressionPlugin = require('compression-webpack-plugin');
// 去除console
const TerserPlugin = require('terser-webpack-plugin');
// const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const path = require('path');
const resolve = (dir) => path.join(__dirname, dir); // 路径
process.env.VUE_APP_VERSION = require('./package.json').version;
const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV);
// const IS_DEV = ['development'].includes(process.env.NODE_ENV);
// port = 8098 npm run dev OR npm run dev --port = 8098
const port = process.env.port || process.env.npm_config_port || 8098; // dev port
module.exports = defineConfig({
// lintOnSave: false, //关闭eslint检查
// publicPath: isDev ? '' : querystring.unescape('<%=request.getContextPath()%>'),
publicPath: process.env.BASE_URL,
// filenameHashing: false,
productionSourceMap: false,
css: {
// requireModuleExtension: true, // 是否开启CSSmodule并保留xxx.module.css后缀
loaderOptions: {
less: {
lessOptions: {
javascriptEnabled: true,
strictMath: false,
noIeCompat: true,
modifyVars: {
'@header-height': '64px',
'@footer-height': '70px',
},
},
},
// sass: {
// additionalData: `
// @use 'sass:math';
// @import "@/styles/global.scss";`
// }
},
},
chainWebpack: (config) => {
// 移除 preload 插件
config.plugins.delete('preload');
// 移除 prefetch 插件
config.plugins.delete('prefetch');
config
.plugin('ignore')
.use(new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /zh-cn$/));
config
// https://webpack.js.org/configuration/devtool/#development
.when(!IS_PROD, (config) => config.devtool('cheap-source-map'));
// 配置相关loader,支持修改,添加和替换相关的loader
config.resolve.alias.set('@', resolve('src'));
// 打包分析
if (IS_PROD) {
// config.optimization.delete('splitChunks');
// config.plugin('webpack-report').use(BundleAnalyzerPlugin, [
// {
// analyzerMode: 'static',
// },
// ]);
}
config.plugin('html').tap((args) => {
args[0].title = 'vue3-antd-admin管理系统';
return args;
});
// svg rule loader
config.module.rule('svg').exclude.add(resolve('src/assets/icons')).end();
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolve('src/assets/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]',
});
},
configureWebpack: (config) => {
// 开启顶级await
config.experiments = {
topLevelAwait: true,
};
config.resolve.fallback = { path: require.resolve('path-browserify') };
if (IS_PROD) {
config.plugins.push(
new TerserPlugin({
terserOptions: {
warnings: false,
format: {
comments: false,
},
compress: {
drop_debugger: true, // 注释console
drop_console: true,
pure_funcs: ['console.log'], // 移除console
},
},
extractComments: false, // 是否将注释提取到一个单独的文件中
parallel: true,
}),
// new CompressionPlugin({
// /* [file]被替换为原始资产文件名。
// [path]替换为原始资产的路径。
// [dir]替换为原始资产的目录。
// [name]被替换为原始资产的文件名。
// [ext]替换为原始资产的扩展名。
// [query]被查询替换。*/
// filename: '[path].gz[query]',
// //压缩算法
// algorithm: 'gzip',
// //匹配文件
// test: /\.js$|\.css$|\.html$/,
// //压缩超过此大小的文件,以字节为单位
// threshold: 10240,
// minRatio: 0.8,
// //删除原始文件只保留压缩后的文件
// deleteOriginalAssets: true
// })
);
config.optimization = {
splitChunks: {
cacheGroups: {
common: {
name: 'chunk-common',
chunks: 'initial',
minChunks: 2,
maxInitialRequests: 5,
minSize: 0,
priority: 1,
reuseExistingChunk: true,
enforce: true,
},
vendors: {
name: 'chunk-vendors',
test: /[\\/]node_modules[\\/]/,
chunks: 'initial',
priority: 2,
reuseExistingChunk: true,
enforce: true,
},
antd: {
name: 'chunk-ant-design-vue',
test: /[\\/]node_modules[\\/]ant-design-vue[\\/]/,
chunks: 'all',
priority: 3,
reuseExistingChunk: true,
enforce: true,
},
},
},
};
}
},
devServer: {
port: port,
proxy: {
// '/mock-api': {
// target: `http://localhost:${port}`,
// changeOrigin: true,
// logLevel: 'debug',
// pathRewrite: {
// '^/mock-api': ''
// }
// },
'^/api': {
// target: process.env.VUE_APP_API_URL,
target: 'http://buqiyuan.site:7001',
ws: true,
changeOrigin: true,
logLevel: 'debug',
pathRewrite: {
'^/api': '',
},
},
},
onBeforeSetupMiddleware: require('./src/mock/mock-server.js'),
},
});