Commit f7ecbb2b authored by 高宇's avatar 高宇

1.全局清空console.log

2. 压缩打包文件
3.配置移动端控制台
parent f9b71eea
......@@ -45,4 +45,78 @@ npm run lint
# 代码格式检查并自动修复
npm run lint -- --fix
```
\ No newline at end of file
```
## 全局清空console.log
1.在main.js文件中配置以下代码
```js
if (process.env.NODE_ENV === 'production') {
if (window) {
window.console.log = function() {}
}
}
```
如果想只在某个特地环境将console.log清空,只需替换production即可
例如 将开发环境的console.log清空
把production替换成.env.development文件中 ENV的值即可
## 压缩打包文件
1. 在package.json引入依赖
```json
"crypto-js": "4.1.1",
"compression-webpack-plugin": "^1.1.12",
```
2. vue.config.js 中配置以下代码
```js
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']
configureWebpack: {
plugins: [
new CompressionWebpackPlugin({
filename: '[path].gz[query]', // 提示compression-webpack-plugin@3.0.0的话asset改为filename
algorithm: 'gzip',
test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
threshold: 10240,
minRatio: 0.8
})
]
}
```
3.在vue.config.js文件configureWebpack对象配置 以下代码
```js
plugins: [
new CompressionWebpackPlugin({
filename: '[path].gz[query]', // 提示compression-webpack-plugin@3.0.0的话asset改为filename
algorithm: 'gzip',
test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
threshold: 10240,
minRatio: 0.8
})
]
```
4. 如果想关闭压缩文件 将第3步注释掉即可
## 配置移动端控制台
1. 位置 在public文件加下添加 vconsole.min.js文件
2. 在 public/index.html 文件夹下配置以下两行代码
```html
<script src="./vconsole.min.js"></script>
<script>new VConsole()</script>
```
3. 去掉移动端控制台 将第二步代码注释掉即可
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment