From 80ce8fe43746426abc054c1cf76b8f733f54b001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BF=A1=E9=91=AB-King?= <45808948@qq.com> Date: Thu, 16 May 2019 19:05:55 +0800 Subject: [PATCH] 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 --- config/config.ts | 14 +++++++++++++- tslint.yml | 9 --------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/config/config.ts b/config/config.ts index c84b8070..dc4b7175 100644 --- a/config/config.ts +++ b/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; diff --git a/tslint.yml b/tslint.yml index e425aa18..7f4cc04d 100644 --- a/tslint.yml +++ b/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