Browse Source

strip console.log in production build

EGOIST 8 years ago
parent
commit
89241c37bf
3 changed files with 16 additions and 2 deletions
  1. 1 0
      package.json
  2. 8 1
      webpack.config.js
  3. 7 1
      yarn.lock

+ 1 - 0
package.json

@@ -35,6 +35,7 @@
     "node-sass": "^4.5.0",
     "postcss-loader": "^1.2.2",
     "sass-loader": "^6.0.2",
+    "strip-loader": "^0.1.2",
     "style-loader": "^0.16.1",
     "url-loader": "^0.5.7",
     "webpack": "^2.2.1",

+ 8 - 1
webpack.config.js

@@ -59,7 +59,14 @@ module.exports = {
                 test: /\.(png|jpg)$/,
                 loader: 'url-loader?limit=40000'
             }
-        ]
+        ].concat(dev ? [] : [
+            {
+                test: /\.js$/,
+                loader: 'strip-loader?strip[]=console.log',
+                enforce: 'pre',
+                include: APP_PATH,
+            }
+        ])
     },
 
     plugins: plugins

+ 7 - 1
yarn.lock

@@ -2015,7 +2015,7 @@ loader-runner@^2.3.0:
   version "2.3.0"
   resolved "http://registry.npm.taobao.org/loader-runner/download/loader-runner-2.3.0.tgz#f482aea82d543e07921700d5a46ef26fdac6b8a2"
 
-loader-utils@^0.2.16:
+loader-utils@^0.2.16, loader-utils@^0.2.6:
   version "0.2.17"
   resolved "http://registry.npm.taobao.org/loader-utils/download/loader-utils-0.2.17.tgz#f86e6374d43205a6e6c60e9196f17c0299bfb348"
   dependencies:
@@ -3388,6 +3388,12 @@ strip-json-comments@~2.0.1:
   version "2.0.1"
   resolved "http://registry.npm.taobao.org/strip-json-comments/download/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
 
+strip-loader@^0.1.2:
+  version "0.1.2"
+  resolved "https://registry.npmjs.org/strip-loader/-/strip-loader-0.1.2.tgz#5166038181599342a424c62a49bbd21902ce8f33"
+  dependencies:
+    loader-utils "^0.2.6"
+
 style-loader@^0.16.1:
   version "0.16.1"
   resolved "http://registry.npm.taobao.org/style-loader/download/style-loader-0.16.1.tgz#50e325258d4e78421dd9680636b41e8661595d10"