-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
77 lines (76 loc) · 3.01 KB
/
webpack.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
/*
* @Author: qianhn@neusoft.com
* @Date: 2020年10月26日13时15分45秒
* @LastEditTime: 2020年11月02日13时55分44秒
* @LastEditors: Please set LastEditors
* @Description: webpack细度配置 文件
* @多读书多看报少吃零食多睡觉
*/
const Timestamp = new Date().getTime()
const path = require('path')
const CompressionPlugin = require('compression-webpack-plugin')
function resolve(dir) {
// __dirname:总是指向被执行 js 文件的绝对路径
return path.join(__dirname, dir)
}
module.exports = {
configureWebpack: {
// output: {
// //更改 js 文件 解决 缓存 问题
// filename: `[name].${process.env.VUE_APP_Version}.${Timestamp}.js`,
// chunkFilename: `[name].${process.env.VUE_APP_Version}.${Timestamp}.js`
// },
plugins: [
new CompressionPlugin({
test: /\.(js|css)(\?.*)?$/i, //需要压缩的文件正则
threshold: 10240, //文件大小大于这个值时启用压缩
deleteOriginalAssets: false //压缩后保留原文件
})
],
// 设置文件别名
resolve: {
alias: {
'@': resolve('src'),
'@assets': resolve('src/assets'),
'@store': resolve('src/store'),
'@views': resolve('src/views'),
'@api': resolve('src/api'),
'@components': resolve('src/components'),
'@utils': resolve('src/utils'),
'@styles': resolve('src/styles'),
'@service': resolve('src/service'),
'@components':resolve('src/components'),
'@config': resolve('src/config'),
'@layOut': resolve('src/layOut'),
'@image':resolve('src/assets/image')
}
}
},
chainWebpack(config) {
config.plugin('preload').tap(() => [
{
rel: 'preload',
// to ignore runtime.js
// https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
include: 'initial'
}
]);
config.module
.rule('images')
.use('url-loader')
.loader('url-loader')
.tap(options => Object.assign(options, { limit: 100 }))
const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
types.forEach(type => addStyleResource(config.module.rule('less').oneOf(type)))
config.optimization.runtimeChunk('single')
}
}
// 动态在类型文件 中 @import mixins.less 混入 因为 例如混入 变量 这种特性 在单文件组件中 无法识别
function addStyleResource(rule) {
rule.use('style-resource')
.loader('style-resources-loader')
.options({
patterns: [path.resolve(__dirname, './src/styles/mixins.less'), path.resolve(__dirname, './src/styles/var.less')]
})
}