-
Notifications
You must be signed in to change notification settings - Fork 24
/
vue.config.js
108 lines (97 loc) · 2.56 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
const path = require('path')
const CompressionPlugin = require('compression-webpack-plugin')
const isProd = process.env.NODE_ENV === 'production'
// 项目目录
// let baseUrl = '/vshop/admin/dist/'
const baseUrl = `${process.env.VUE_APP_BASE_URL}`
function resolve (dir) {
return path.join(__dirname, dir)
}
module.exports = {
publicPath: isProd ? baseUrl : '/',
productionSourceMap: false,
lintOnSave: !isProd,
// 开启gzip 压缩
configureWebpack: config => {
const plugins = []
if (isProd) {
plugins.push(
new CompressionPlugin({
test: /\.js$|\.html$|\.css$/, // 匹配的文件名
threshold: 8192, // 对 超过8K的数据进行压缩
deleteOriginalAssets: false // 是否删除源文件
})
)
}
return {
plugins
}
},
chainWebpack: config => {
const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
types.forEach(type => addStyleResource(config.module.rule('scss').oneOf(type)))
// svg
const svgRule = config.module.rule('svg')
svgRule.uses.clear()
svgRule
.include
.add(resolve('src/assets/svg-icons/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'admin-[name]'
})
.end()
config
// 开发环境
.when(process.env.NODE_ENV === 'development',
// sourcemap不包含列信息
config => config.devtool('cheap-source-map')
)
// image exclude
const imagesRule = config.module.rule('images')
imagesRule
.test(/\.(png|jpe?g|gif|webp|svg)(\?.*)?$/)
.exclude
.add(resolve('src/assets/svg-icons/icons'))
.end()
config.resolve.alias
.set('vue$', 'vue/dist/vue.esm.js')
.set('@', resolve('src'))
.set('assets', resolve('src/assets'))
.set('utils', resolve('src/utils'))
},
devServer: {
// proxy: {
// "/": {
// target: "http://192.168.29.80:8080",
// changeOrigin: true,
// ws: false,
// secure: false
// },
// },
port: 8080
},
pluginOptions: {
'style-resources-loader': {
preProcessor: 'scss',
patterns: []
}
},
transpileDependencies: [
'vue-echarts',
'resize-detector'
]
}
function addStyleResource (rule) {
rule.use('style-resource')
.loader('style-resources-loader')
.options({
patterns: [
// 全局共享样式
path.resolve(__dirname, './src/styles/_variables.scss'),
path.resolve(__dirname, './src/styles/mixins.scss')
]
})
}