Procházet zdrojové kódy

remove console.log in production 减少干扰,方便最终确认构建错误

Michael Wang před 6 roky
rodič
revize
d8b89e6921
3 změnil soubory, kde provedl 16 přidání a 5 odebrání
  1. 1 0
      package.json
  2. 10 5
      vue.config.js
  3. 5 0
      yarn.lock

+ 1 - 0
package.json

@@ -39,6 +39,7 @@
     "babel-core": "7.0.0-bridge.0",
     "babel-eslint": "^10.0.1",
     "babel-jest": "^23.6.0",
+    "babel-plugin-transform-remove-console": "^6.9.4",
     "eslint": "^5.8.0",
     "eslint-plugin-vue": "^5.0.0",
     "iview-loader": "^1.2.2",

+ 10 - 5
vue.config.js

@@ -42,6 +42,15 @@ let proxy = {
 // }
 
 var webpack = require("webpack");
+
+const plugins = [];
+// Ignore all locale files of moment.js
+// TODO: use webpack stats to check if iview locale matters
+plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment|iview$/));
+if (process.env.NODE_ENV === "production") {
+  plugins.push("transform-remove-console");
+}
+
 module.exports = {
   devServer: {
     proxy
@@ -59,10 +68,6 @@ module.exports = {
       .end();
   },
   configureWebpack: {
-    plugins: [
-      // Ignore all locale files of moment.js
-      // TODO: use webpack stats to check if iview locale matters
-      new webpack.IgnorePlugin(/^\.\/locale$/, /moment|iview$/)
-    ]
+    plugins
   }
 };

+ 5 - 0
yarn.lock

@@ -1650,6 +1650,11 @@ babel-plugin-transform-object-rest-spread@^6.26.0:
     babel-plugin-syntax-object-rest-spread "^6.8.0"
     babel-runtime "^6.26.0"
 
+babel-plugin-transform-remove-console@^6.9.4:
+  version "6.9.4"
+  resolved "https://registry.yarnpkg.com/babel-plugin-transform-remove-console/-/babel-plugin-transform-remove-console-6.9.4.tgz#b980360c067384e24b357a588d807d3c83527780"
+  integrity sha1-uYA2DAZzhOJLNXpYjYB9PINSd4A=
+
 babel-plugin-transform-strict-mode@^6.24.1:
   version "6.24.1"
   resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758"