-
Notifications
You must be signed in to change notification settings - Fork 9
/
vue.config.js
139 lines (135 loc) · 3.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
const baseUrl = require('./src/service/env')
const path = require('path')
const resolve = (dir) => path.join(__dirname, dir)
const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV)
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const cdn = {
externals: {
vue: 'Vue',
vuex: 'Vuex',
'vue-router': 'VueRouter',
axios: 'axios',
vuetify: 'vuetify',
less: 'less',
jszip: 'JSZip',
prettier: 'prettier',
},
js: [
'https://cdn.staticfile.org/vue/2.6.11/vue.min.js',
'https://cdn.staticfile.org/vuex/3.5.1/vuex.min.js',
'https://cdn.staticfile.org/vue-router/3.2.0/vue-router.min.js',
'https://cdn.staticfile.org/axios/0.19.2/axios.min.js',
'https://cdn.staticfile.org/vuetify/2.4.0/vuetify.min.js',
'https://cdn.staticfile.org/less.js/3.12.2/less.min.js',
'https://cdn.staticfile.org/jszip/3.7.1/jszip.min.js',
'https://cdn.staticfile.org/prettier/2.5.1/standalone.min.js',
]
}
// 本地环境是否需要使用cdn
const devNeedCdn = false
module.exports = {
publicPath: IS_PROD ? '/' : '/',
outputDir: 'dist',
assetsDir: 'assets',
lintOnSave: false,
runtimeCompiler: true,
productionSourceMap: !IS_PROD,
parallel: require('os').cpus().length > 1,
pwa: {},
devServer: {
historyApiFallback: { index: '/index.html' },
proxy: {
'/api': {
target: baseUrl.server,
pathRewrite: {
'^/api': '',
},
},
'/githubApi': {
target: 'https://api.github.com',
secure: true,
changeOrigin: true,
pathRewrite: {
'^/githubApi': '',
},
},
'/qiNiuCdn': {
target: 'http://picstore.lliiooiill.cn',
secure: true,
changeOrigin: true,
pathRewrite: {
'^/qiNiuCdn': '',
},
},
'/qiNiu': {
target: 'http://upload-z2.qiniup.com',
pathRewrite: {
'^/qiNiu': '',
},
},
'/images': {
target: 'http://images.lliiooiill.cn',
pathRewrite: {
'^/images': '',
},
}
},
},
configureWebpack: config => {
config.module.rules.push({
/*test: /\.extension$/,*/
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto'
})
//gzip压缩
const productionGzipExtensions = ['html', 'js', 'css']
config.plugins.push(
new CompressionWebpackPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp(
'\\.(' + productionGzipExtensions.join('|') + ')$'
),
threshold: 10240, // 只有大小大于该值的资源会被处理 10240
minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
deleteOriginalAssets: false // 删除原文件
})
)
if (IS_PROD || devNeedCdn) config.externals = cdn.externals
},
chainWebpack: (config) => {
config.resolve.alias
.set('@', resolve('src'))
.set('@styles', resolve('src/styles'))
.set('@assets', resolve('src/assets'))
.set('@service', resolve('src/service'))
.set('@components', resolve('src/components'))
.set('@views', resolve('src/views'))
.set('@store', resolve('src/store'))
.set('@utils', resolve('src/utils'))
.set('@plugins', resolve('src/plugins'))
config.plugin('html').tap(args => {
// 生产环境或本地需要cdn时,才注入cdn
if (IS_PROD || devNeedCdn) args[0].cdn = cdn
return args
})
if (IS_PROD) {
config
.plugin('webpack-bundle-analyzer')
.use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
}
},
css: {
extract: IS_PROD,
sourceMap: false,
loaderOptions: {
scss: {
additionalData: `@import '@styles/main.scss';`,
},
},
},
transpileDependencies: [
'vuetify'
]
}