-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
177 lines (170 loc) · 5.11 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
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const { HashedModuleIdsPlugin } = require('webpack');
const PrerenderSPAPlugin = require('prerender-spa-plugin');
// 类似于 SSR 提前渲染单个页面
// const Renderer = PrerenderSPAPlugin.PuppeteerRenderer;
const path = require('path');
function resolve() {
return path.resolve.apply(null, [...arguments]);
}
// cdn预加载使用
const externals = {
'vue': 'Vue',
'vue-router': 'VueRouter',
'vuex': 'Vuex',
'axios': 'axios',
"element-ui": "ELEMENT",
// "vue-qriously": "VueQriously"
}
const cdn = {
// 开发环境
dev: {
css: [
'https://unpkg.com/element-ui/lib/theme-chalk/index.css'
],
js: []
},
// 生产环境
build: {
// css: [
// 'https://unpkg.com/element-ui/lib/theme-chalk/index.css'
// ],
js: [
'https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js',
'https://cdn.jsdelivr.net/npm/[email protected]/dist/vue-router.min.js',
'https://cdn.jsdelivr.net/npm/[email protected]/dist/vuex.min.js',
'https://cdn.jsdelivr.net/npm/[email protected]/dist/axios.min.js',
'https://cdn.jsdelivr.net/npm/[email protected]/dist/axios.min.js',
// 'https://cdn.jsdelivr.net/npm/vue-qriously',
'https://unpkg.com/element-ui/lib/index.js',
]
}
}
module.exports = {
publicPath: '/',
chainWebpack: config => {
// webpack 会默认给commonChunk打进chunk-vendors,所以需要对webpack的配置进行delete
if (process.env.NODE_ENV === 'production') {
config.optimization.delete('splitChunks');
config.plugin('html').tap(args => {
args[0].cdn = cdn.build
return args
});
// config.externals = externals;
}
// config
// .plugin('webpack-bundle-analyzer')
// .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
},
configureWebpack: {
resolve: {
alias: {
'assets': '@/assets',
'common': '@/common',
'components': '@/components',
'views': '@/views',
}
},
plugins: [
new CompressionWebpackPlugin({
test: /\.(js|css|svg|woff|ttf|json|html)$/,
threshold: 10240,
minRatio: 0.8
}),
new HashedModuleIdsPlugin(),
],
optimization: {
minimizer: [
new UglifyJsPlugin({
sourceMap: false,
uglifyOptions: {
output: {
comments: false
},
compress: {
drop_console: true,//console
drop_debugger: true,
pure_funcs: ['console.log']//移除console
}
}
})
],
splitChunks: {
chunks: 'all',
minSize: 30000, // 字节 引入的文件大于30kb才进行分割
minChunks: 1, // 模块至少使用次数
maxAsyncRequests: 5, // 同时加载的模块数量最多是5个,只分割出同时引入的前5个文件
maxInitialRequests: 3, // 首页加载的时候引入的文件最多3个
automaticNameDelimiter: '~', // 缓存组和生成文件名称之间的连接符
name: true, // 缓存组里面的filename生效,覆盖默认命名
cacheGroups: {
libs: {
name: 'chunk-libs',
test: /[\\/]node_modules[\\/]/,
priority: -10,
chunks: 'initial'
},
commons: {
name: 'chunk-commons',
test: resolve('src/components'), // can customize your rules
minChunks: 2, // minimum common number
priority: 10,
reuseExistingChunk: true
},
}
},
runtimeChunk: {
name: 'manifest'
},
},
externals
},
css: {
extract: false
},
devServer: {
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
ws: true,
pathRewrite: {
'^/api': ''
}
},
'm7': {
target: 'http://m7.music.126.net',
changeOrigin: true,
ws: true,
pathRewrite: {
'^/m7': ''
}
},
'm701': {
target: 'http://m701.music.126.net',
changeOrigin: true,
ws: true,
pathRewrite: {
'^/m701': ''
}
},
'm8': {
target: 'http://m8.music.126.net',
changeOrigin: true,
ws: true,
pathRewrite: {
'^/m8': ''
}
},
'm801': {
target: 'http://m801.music.126.net',
changeOrigin: true,
ws: true,
pathRewrite: {
'^/m801': ''
}
}
}
},
}