Quellcode durchsuchen

Tweak console dev (#4133)

* :lipstick: allow use console in dev, auto remove in production.

* fix: use uglifyJSOptions

* fix: config.ts using NODE_ENV identify isProd
信鑫-King vor 6 Jahren
Ursprung
Commit
80ce8fe437
2 geänderte Dateien mit 13 neuen und 10 gelöschten Zeilen
  1. 13 1
      config/config.ts
  2. 0 9
      tslint.yml

+ 13 - 1
config/config.ts

@@ -7,7 +7,7 @@ import webpackPlugin from './plugin.config';
 
 const { pwa, primaryColor } = defaultSettings;
 // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
-const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, TEST } = process.env;
+const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, TEST, NODE_ENV } = process.env;
 
 const plugins: IPlugin[] = [
   [
@@ -67,6 +67,17 @@ if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
     },
   ]);
 }
+const uglifyJSOptions = NODE_ENV === 'production'
+  ? {
+      uglifyOptions: {
+        // remove console.* except console.error
+        compress: {
+          drop_console: true,
+          pure_funcs: [ 'console.error' ],
+        },
+      },
+    }
+  : {};
 
 export default {
   // add for transfer to umi
@@ -145,5 +156,6 @@ export default {
   manifest: {
     basePath: '/',
   },
+  uglifyJSOptions,
   chainWebpack: webpackPlugin,
 } as IConfig;

+ 0 - 9
tslint.yml

@@ -20,15 +20,6 @@ rules:
   no-bitwise: true
   no-conditional-assignment: true
   no-consecutive-blank-lines: true
-  no-console:
-    - true
-    - debug
-    - info
-    - log
-    - time
-    - timeEnd
-    - trace
-    - warn
   no-construct: true
   no-debugger: true
   no-duplicate-variable: true