-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
88 lines (84 loc) · 2.83 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
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const path = require('path')
const isProduction = process.env.NODE_ENV === 'production'
function resolve (dir) {
return path.join(__dirname, dir)
}
module.exports = {
publicPath: process.env.VUE_APP_PUBLIC_PATH,
lintOnSave: false,
baseUrl: undefined,
outputDir: process.env.VUE_APP_OUTPUT_DIR,
assetsDir: process.env.VUE_APP_ASSETS_DIR,
indexPath: process.env.VUE_APP_INDEX_PATH,
runtimeCompiler: false,
productionSourceMap: false,
parallel: undefined,
css: undefined,
configureWebpack (config) {
return {
output: {
filename: `${process.env.VUE_APP_ASSETS_DIR}/js/[name].${isProduction ? '[contenthash:8].' : ''}js`,
chunkFilename: `${process.env.VUE_APP_ASSETS_DIR}/js/[name].js?[contenthash:8]`
},
plugins: isProduction ? [new BundleAnalyzerPlugin({ analyzerMode: 'static' })] : [],
optimization: {
minimizer: [new OptimizeCSSAssetsPlugin({ assetNameRegExp: /\.css(\?[a-z0-9]{8})?$/g })]
}
}
},
chainWebpack (config) {
// 规则配置
config.module
.rule('pug')
.uses.clear()
.end()
.oneOf('vue') // 这条规则应用到 Vue 组件内的 `<template lang="pug">`
.resourceQuery(/^\?vue/)
.use('vue')
.loader('pug-plain-loader')
.end()
.end()
.oneOf('pug') // 这条规则应用到 JavaScript 内的 pug 导入
.use('pug')
.loader('raw-loader')
.end()
.use('vue')
.loader('pug-plain-loader')
// 别名配置
config.resolve.alias
.set('@font', resolve('src/assets/font'))
.set('@icon', resolve('src/assets/icon'))
.set('@images', resolve('src/assets/images'))
.set('@reset', resolve('src/common/reset'))
.set('@assets', resolve('src/assets'))
.set('@components', resolve('src/components'))
.set('@public', resolve('public'))
// 添加扩展名
config.resolve.extensions
.add('.less')
.add('.pug')
// 插件修改
if (isProduction) {
config.plugin('extract-css')
.tap(args => {
args[0].filename = `${process.env.VUE_APP_ASSETS_DIR}/css/[name].[contenthash:8].css`
args[0].chunkFilename = `${process.env.VUE_APP_ASSETS_DIR}/css/[name].css?[contenthash:8]`
return args
})
}
// 取消预加载,减小带宽消耗
config.plugins.delete('prefetch')
// 这个插件在源码中写死了只优化.css结尾的文件,提取出来的文件是.css?hash没法匹配
config.plugins.delete('optimize-css')
},
pluginOptions: {
'style-resources-loader': { // 自动导入样式变量
preProcessor: 'less',
patterns: [
resolve('./src/common/reset/import.less')
]
}
}
}