From 131c98f7555c9caea640548c38a33a339733b5e9 Mon Sep 17 00:00:00 2001 From: StEve Young <2747745470@qq.com> Date: Tue, 5 Mar 2019 17:25:33 +0800 Subject: [PATCH] fix: should not display logs when it's in production mode (#25) --- package.json | 2 +- rollup.config.js | 20 +++++++++++++++----- src/utils/logger.js | 5 +++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 66a1c29..ccaeda0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tua-api", - "version": "1.0.0", + "version": "1.0.1", "description": "🏗 A common tool helps converting configs to api functions", "main": "dist/TuaApi.cjs.js", "module": "dist/TuaApi.esm.js", diff --git a/rollup.config.js b/rollup.config.js index 7172795..d01dd36 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -41,23 +41,33 @@ const plugins = [ nodeResolve(), commonjs(), babel(), - replace({ - 'process.env.NODE_ENV': JSON.stringify('production'), - }), ] +const env = 'process.env.NODE_ENV' const external = ['axios', 'fetch-jsonp'] export default [{ input, - output: [ output.cjs, output.esm, output.umd ], + output: [ output.cjs, output.esm ], plugins, external, +}, { + input, + output: output.umd, + external, + plugins: [ + ...plugins, + replace({ [env]: '"development"' }), + ], }, { input, output: { ...output.umd, file: 'dist/TuaApi.umd.min.js', }, - plugins: [ ...plugins, uglify() ], external, + plugins: [ + ...plugins, + replace({ [env]: '"production"' }), + uglify(), + ], }] diff --git a/src/utils/logger.js b/src/utils/logger.js index 7efb3d3..bc7bcd4 100644 --- a/src/utils/logger.js +++ b/src/utils/logger.js @@ -4,8 +4,9 @@ * @param {any} out 具体的输出内容 */ const logByType = (type) => (...out) => { - /* istanbul ignore else */ - if (process.env.NODE_ENV === 'test') return + const env = process.env.NODE_ENV + /* istanbul ignore next */ + if (env === 'test' || env === 'production') return /* istanbul ignore next */ console[type](`[TUA-API]:`, ...out)