-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
145 lines (131 loc) · 3.96 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'use strict'
const path = require('path')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const CompressionWebpackPlugin = require('compression-webpack-plugin') // gzip压缩
const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i // gzip匹配文件规则
const NOT_DEV = process.env.NODE_ENV !== 'development'
const globalConfig = require('./src/config/index.js')
const resolve = dir => path.join(__dirname, dir)
const addOptions = {
preserveWhitespace: true
}
module.exports = {
publicPath: '',
// 根据环境去打包
outputDir: process.env.VUE_APP_OUTPUTDIR,
//是否使用包含运行时编译器的 Vue 构建版本
runtimeCompiler: true,
//不在production环境使用SourceMap
productionSourceMap: false,
css: {
loaderOptions: {
less: {
javascriptEnabled: true,
}
}
},
configureWebpack: (config) => {
config.name = globalConfig.baseTitle //用于设置public/index.html的默认title
config.entry.app = ['babel-polyfill', './src/main.js']; //入口文件
let plugins = [
new UglifyJsPlugin({
uglifyOptions: {
warnings: false,
compress: {
// drop_console:true,
drop_debugger: true
},
output: {
// 去掉注释内容
comments: false,
}
},
sourceMap: false,
parallel: true,
}), //删除console插件
new CompressionWebpackPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: productionGzipExtensions,
threshold: 10240, // 只处理比这个值大的资源,按字节计算
minRatio: 0.8, // 只有压缩率比这个值小的资源才会被处理
deleteOriginalAssets: false //是否删除原始资源 默认false
})
];
//只有打包生产环境才需要将console删除
if (NOT_DEV) {
config.mode = 'production';
config.plugins = [...config.plugins, ...plugins];
config.performance = {
maxEntrypointSize: 10000000,
maxAssetSize: 30000000
}
}
},
//允许对内部的 webpack 配置进行更细粒度的修改。
chainWebpack: (config) => {
//命名
config.resolve.alias
.set('@', resolve('src'))
.set('@api', resolve('src/api'))
.set('@assets', resolve('src/assets'))
.set('@components', resolve('src/components'))
.set('@router', resolve('src/router'))
.set('@store', resolve('src/store'))
.set('@utils', resolve('src/utils'))
.set('@views', resolve('src/views'))
.set('vue-i18n', 'vue-i18n/dist/vue-i18n.cjs.js');
//打包文件带hash
config.output.filename('[name].[hash].js').end();
//为了补删除换行而加的配置
config.module
.rule("vue")
.use("vue-loader")
.loader("vue-loader")
.tap(options => {
// modify the options...
options.compilerOptions = addOptions;
return options;
});
config.module.rule('compile')
.test(/\.js$/)
.include
.add(resolve('src'))
.add(resolve('test'))
.add(resolve('node_modules/webpack-dev-server/client'))
.add(resolve('node_modules'))
.end()
.use('babel')
.loader('babel-loader')
.options({
presets: [
['@babel/preset-env', {
modules: false
}]
]
});
},
devServer: {
// port: 8080,
// open: true, //配置自动启动浏览器
proxy: {
'/api': {
target: process.env.VUE_APP_API_HOST,
ws: true,
changeOrigin: true,
secure: false,
},
}
},
pluginOptions: {
i18n: {
locale: 'en',
fallbackLocale: 'zn',
localeDir: 'locales',
enableLegacy: true,
runtimeOnly: false,
compositionOnly: true,
fullInstall: true
}
}
}