-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathvue.config.js
95 lines (92 loc) · 2.75 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 webpack = require('webpack')
const TerserPlugin = require('terser-webpack-plugin')// 去console插件
const CompressionWebpackPlugin = require('compression-webpack-plugin')// gzip压缩插件
const resolve = dir => path.join(__dirname, dir)
module.exports = {
// 基本路径
publicPath: './',
// 输出文件目录
outputDir: process.env.outputDir,
// 用于嵌套生成的静态资产(js,css,img,fonts)的目录
assetsDir: '',
// 指定生成的 index.html 的输出路径 (相对于 outputDir)
indexPath: 'index.html',
// 静态资源在它们的文件名中包含了 hash 以便更好的控制缓存
filenameHashing: true,
// 以多页模式构建应用程序
pages: undefined,
// eslint-loader 是否在保存的时候检查
lintOnSave: true,
// 是否使用包含运行时编译器的Vue核心的构建
runtimeCompiler: false,
// 默认情况下babel-loader忽略其中的所有文件node_modules
transpileDependencies: [],
// 生产环境sourceMap
productionSourceMap: false,
// 设置生成的 HTML 中 <link rel="stylesheet"> 和 <script> 标签的 crossorigin 属性
crossorigin: undefined,
// 在生成的 HTML 中的 <link rel="stylesheet"> 和 <script> 标签上启用 Subresource Integrity (SRI)
integrity: false,
// webpack配置
configureWebpack: config => {
// config.name = name
const plugins = [
// 忽略moment locale文件
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// 去console
new TerserPlugin({
terserOptions: {
warnings: false,
compress: {
drop_debugger: true,
drop_console: true,
},
},
sourceMap: false,
parallel: true,
}),
// gzip压缩
new CompressionWebpackPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp(
'\\.(' +
['js', 'css'].join('|') +
')$',
),
threshold: 10240,
minRatio: 0.8,
}),
]
if (process.env.NODE_ENV === 'production') {
config.plugins = [...config.plugins, ...plugins]
}
},
chainWebpack: config => {
config.resolve.alias.set('@', resolve('src'))
},
// css相关配置
css: {
// 启用 CSS modules
requireModuleExtension: true,
// 开启 CSS source maps
sourceMap: false,
// css预设器配置项
loaderOptions: {}
},
// webpack-dev-server配置
devServer: {
open: true,
host: '0.0.0.0',
port: 8080,
https: false,
hotOnly: false,
proxy: null // string | Object
},
// enabled by default if the machine has more than 1 cores
parallel: require('os').cpus().length > 1,
pwa: {},
// 第三方插件选项
pluginOptions: {}
}