Skip to content

Commit 8840e45

Browse files
author
cpzhang
committed
remove console.log for production
1 parent 93b2956 commit 8840e45

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

docs/2-webpack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ mode为production时,默认提供所有可能的优化,如代码压缩/作用
380380
- image-webpack-loader
381381
- imagemin-webpack-plugin
382382
383+
### 生产模式清除console.log
384+
webpack4的production模式并没有对console.log进行清除,可以使用
385+
- strip-loader,可以清除任何你想清除的function
386+
- webpack-clear-console
387+
383388
## 插件
384389
### CSS抽离
385390
- ExtractTextWebpackPlugin

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"file-loader": "^1.1.11",
3030
"html-webpack-plugin": "^3.0.6",
3131
"react-hot-loader": "^4.0.0",
32+
"strip-loader": "^0.1.2",
3233
"style-loader": "^0.20.2",
3334
"url-loader": "^1.0.1",
3435
"webpack": "^4.1.0",

webpack.prod.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const base = require('./webpack.config.js');
77
/*const UglifyJsPlugin = require('uglifyjs-webpack-plugin');*/
88
/*const ExtractTextPlugin = require('extract-text-webpack-plugin');*/
99
/*const MiniCssExtractPlugin = require("mini-css-extract-plugin");*/
10+
const WebpackStrip = require('strip-loader');
1011

1112
module.exports = merge(base, {
1213
mode: 'production',
@@ -17,6 +18,7 @@ module.exports = merge(base, {
1718
},
1819
module: {
1920
rules: [
21+
{test: /\.jsx?$/, use: WebpackStrip.loader('console.log'), exclude: /node_modules/}
2022
/*{
2123
test: /\.css$/,
2224
use: ExtractTextPlugin.extract({

0 commit comments

Comments
 (0)