-
Notifications
You must be signed in to change notification settings - Fork 14
/
vue.config.js
95 lines (93 loc) · 2.47 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
const path = require('path')
const fs = require('fs');
const FileManagerPlugin = require('filemanager-webpack-plugin')
function resolvePath (dir) {
return path.resolve(__dirname, '.', dir)
}
function getCompressionName () {
try {
const projectName = JSON.parse(fs.readFileSync('package.json')).name;
const projectVersion = JSON.parse(fs.readFileSync('package.json')).version;
return `./build/${projectName}-${projectVersion}.tar.gz`;
} catch (e) {
return './build/dist.tar.gz';
}
}
const isProd = process.env.NODE_ENV === 'production'
module.exports = {
lintOnSave: false,
publicPath: process.env.BASE_URL,
assetsDir: 'static', // 配置js、css静态资源二级目录的位置
devServer: {
port: 9090,
proxy: process.env.PROXY_SERVER
},
configureWebpack: {
devtool: process.env.NODE_ENV === 'dev' ? 'eval-source-map' : undefined,
resolve: {
alias: {
'vue$': 'vue/dist/vue.common.js'
}
}
},
chainWebpack: config => {
const oneOfsMap = config.module.rule('scss').oneOfs.store;
oneOfsMap.forEach(item => {
item
.use('style-resources-loader')
.loader('style-resources-loader')
.options({
patterns: './src/assets/css/variable.scss'
})
.end()
})
// 定义组件中文案翻译
config.module
.rule('i18n')
.resourceQuery(/blockType=i18n/)
.type('javascript/auto')
.use('i18n')
.loader('@kazupon/vue-i18n-loader')
.end()
// 配置项目标题
config
.plugin('html')
.tap(args => {
args[0].title = 'Byzer Notebook'
return args
})
.end()
// 让其他svg loader不要对src/icons进行操作
config.module
.rule('svg')
.exclude.add(resolvePath('src/icons/svg'))
.end()
// 使用svg-sprite-loader 对 src/icons下的svg进行操作
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolvePath('src/icons/svg'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]'
})
.end()
if (isProd) {
config.plugin('filemanager')
.use(
new FileManagerPlugin({
events: {
onEnd: [{
delete: [ getCompressionName() ],
archive: [
{ source: './dist', format: 'tar', destination: getCompressionName()}
]
}]
}
})
)
}
}
}