forked from ggymm/data-view-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
120 lines (110 loc) · 3.16 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
const path = require('path')
// noinspection NpmUsedModulesInstalled
const webpack = require('webpack')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const buildDate = JSON.stringify(new Date().toLocaleString())
// 如果没有网络,改为false
const isCdn = true
function resolve(dir) {
return path.join(__dirname, dir)
}
const assetsCDN = {
externals: {
'vue': 'Vue',
'vue-router': 'VueRouter',
'vuex': 'Vuex',
'axios': 'axios',
'@vue/composition-api': 'VueCompositionAPI',
'echarts': 'echarts',
'vue-echarts': 'VueECharts',
'moment': 'moment',
'ant-design-vue': 'antd'
},
css: [
'https://cdn.jsdelivr.net/npm/[email protected]/dist/antd.css'
],
js: [
'https://cdn.jsdelivr.net/npm/vue@latest/dist/vue.min.js',
'https://cdn.jsdelivr.net/npm/vue-router@latest/dist/vue-router.min.js',
'https://cdn.jsdelivr.net/npm/vuex@latest/dist/vuex.min.js',
'https://cdn.jsdelivr.net/npm/axios@latest/dist/axios.min.js',
'https://cdn.jsdelivr.net/npm/@vue/[email protected]',
'https://cdn.jsdelivr.net/npm/echarts@latest',
'https://cdn.jsdelivr.net/npm/vue-echarts@latest',
'https://cdn.jsdelivr.net/npm/[email protected]/min/moment.min.js',
'https://cdn.jsdelivr.net/npm/[email protected]/dist/antd.min.js'
]
}
// noinspection JSUnusedGlobalSymbols
const vueConfig = {
publicPath: '/data-view-web',
outputDir: 'build',
devServer: {
port: 8000
},
css: {
loaderOptions: {
less: {
modifyVars: {
'primary-color': '#8ab4f8',
'border-radius-base': '2px'
},
javascriptEnabled: true
}
}
},
productionSourceMap: false,
configureWebpack: {
plugins: [
new CompressionWebpackPlugin({
algorithm: 'gzip',
test: new RegExp('\\.(js|css)$'),
threshold: 10240,
minRatio: 0.8,
deleteOriginalAssets: false
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new webpack.DefinePlugin({
APP_VERSION: `"${require('./package.json').version}"`,
BUILD_DATE: buildDate
})
],
optimization: {
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
// get the name. E.g. node_modules/packageName/not/this/part.js
// or node_modules/packageName
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
// npm package names are URL-safe, but some servers don't like @ symbols
return `npm.${packageName.replace('@', '')}`
}
}
}
}
},
resolve: {
alias: {
'@': resolve('src')
}
},
// if prod, add externals
externals: isCdn ? assetsCDN.externals : {}
},
chainWebpack: (config) => {
// if prod is on
// assets require on cdn
if (isCdn) {
config.plugin('html').tap(args => {
args[0].cdn = assetsCDN
return args
})
}
}
}
// noinspection JSPrimitiveTypeWrapperUsage
module.exports = vueConfig