-
Notifications
You must be signed in to change notification settings - Fork 98
/
vue.config.js
118 lines (116 loc) · 3.34 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
const path = require('path');
const devMode = process.env.NODE_ENV !== 'production';
const compressionWebpackPlugin = require('compression-webpack-plugin');
const cssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const miniCssExtractPlugin = require('mini-css-extract-plugin');
function resolve(dir) {
return path.resolve(__dirname, dir)
}
module.exports = {
filenameHashing:true,
lintOnSave:false,
css:{
requireModuleExtension:true,
},
productionSourceMap:false,
devServer:{
compress:true,
port:2016,
disableHostCheck:true,
hot:true,
open:true,
},
parallel:require('os').cpus().length > 1,
configureWebpack:cfg => {
if (process.env.VUE_APP_PLATFORM === 'h5') {
cfg.performance = {
hints:'warning',
maxEntrypointSize:20480000,
maxAssetSize:20480000,
assetFilter:function (assetFilename) {
return assetFilename.endsWith('.js');
}
};
cfg.plugins.push(new compressionWebpackPlugin({
algorithm:'gzip',
test:new RegExp('\\.(' + ['ts', 'js', 'css'].join('|') + ')$'),
threshold:10240,
minRatio:0.8
}));
cfg.optimization = {
moduleIds: 'size',
minimize: true,
minimizer: [
new cssMinimizerPlugin(),
],
splitChunks: {
chunks: 'async',
minSize: 20000,
maxSize: 0,
minChunks: 1,
maxAsyncRequests: 5,
maxInitialRequests: Infinity,
automaticNameDelimiter: '~',
name: true,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
return `npm.${packageName.replace('@', '')}`;
},
priority: 9,
minChunks: 1,
reuseExistingChunk: true,
enforce: true,
// chunks: 'all',
},
commons: {
name: 'commons',
priority: 8,
minChunks: 2,
reuseExistingChunk: true,
enforce: true,
chunks: 'all',
},
default: {
minChunks: 2,
priority: 7,
}
}
}
};
}
cfg.resolve.extensions = ['.ts', '.js', '.vue', '.json'];
cfg.resolve.alias = {
...cfg.resolve.alias,
'@':resolve('src'),
'assets':resolve('src/assets'),
'builds':resolve('src/builds'),
'components':resolve('src/components'),
'mixins':resolve('src/mixins'),
'pages':resolve('src/pages'),
'plugins':resolve('src/plugins'),
'projects':resolve('src/projects'),
'service':resolve('src/service'),
'static':resolve('src/static'),
'utils':resolve('src/utils'),
};
},
chainWebpack: cfg => {
cfg.plugins.delete('prefetch');
if (process.env.VUE_APP_PLATFORM === 'h5' && !devMode) {
cfg.module.loaders = [
{
test: /.s?css$/,
use: [miniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
}
];
}
if (process.env.npm_config_report && !devMode) {
cfg.plugin('webpack-bundle-analyzer')
.use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
.end();
}
}
};