-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
75 lines (69 loc) · 1.92 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
'use strict'
const path = require('path')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
function resolve(dir) {
return path.join(__dirname, dir)
}
// port = 9527 npm run dev OR npm run dev --port = 9527
const port = process.env.port || process.env.npm_config_port || 9527 // dev port
const isDev = process.env.NODE_ENV === 'development'
const vueConfig = {
publicPath: '/vue3-admin-typescript/',
productionSourceMap: false,
devServer: {
port: port,
open: true,
overlay: {
warnings: false,
errors: true,
},
before: require('./mock/mock-server.js'),
},
configureWebpack: {
resolve: {
alias: {
'@': resolve('src'),
},
},
// webpack plugins
plugins: [
Components({
resolvers: [ElementPlusResolver()],
}),
],
},
chainWebpack(config) {
// when there are many pages, it will cause too many meaningless requests
config.plugins.delete('prefetch')
// set svg-sprite-loader
config.module.rule('svg').exclude.add(resolve('src/icons')).end()
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolve('src/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]',
})
.end()
config.when(!isDev, (config) => {
config.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
libs: {
name: 'chunk-libs',
test: /[\\/]node_modules[\\/](?!element-plus)/,
priority: 20,
chunks: 'initial', // only package third parties that are initially dependent
},
},
})
// https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
config.optimization.runtimeChunk('single')
})
},
}
module.exports = vueConfig