简体   繁体   English

Uglify JS - 仅删除console.log

[英]Uglify JS - remove only console.log

I have a question regarding the Uglify JS module, in the usecase of webpack plugin. 我有一个关于Uglify JS模块的问题,在webpack插件的用例中。

My codebase have several console.log statements around the code for debugging purposes localy, it will only be printede out in development mode, but they are still taking up space in the codebase and i dont what them in the production build but, i would like to keep my console.error and console.warn still. 我的代码库在代码周围有几个console.log语句用于调试目的,它只会在开发模式下打印出来,但是它们仍占用代码库中的空间,我不知道它们在生产构建中是什么,但我希望保持我的console.errorconsole.warn仍然。

I know the Uglify JS have key drop_console flag but that kills every console output there is and i still want the warnings and errors in my console. 我知道Uglify JS有关键的drop_console标志,但它会杀死每个控制台输出,我仍然想要控制台中的警告和错误。

The reason for this question is i have a custom error handler than ships errors to Sentry, and I want to read the error in the console when it happens, so i use the error and warning console out put. 这个问题的原因是我有一个自定义错误处理程序,而不是向Sentry发送错误,我想在控制台发生时读取错误,所以我使用错误和警告控制台输出。

From docs : 来自docs

drop_console (default: false ) -- Pass true to discard calls to console.* functions. drop_console (默认值: false ) - 传递true以放弃对console.*函数的调用。 If you wish to drop a specific function call such as console.info and/or retain side effects from function arguments after dropping the function call then use pure_funcs instead . 如果你希望删除一个特定的函数调用,如console.info和/或在删除函数调用后保留函数参数的副作用,那么请改用pure_funcs

... ...

pure_funcs (default: null ) -- [...] You can pass pure_funcs: [ 'Math.floor' ] to let it know that this function won't produce any side effect, in which case the whole statement would get discarded . pure_funcs (默认值: null ) - [...]你可以传递pure_funcs: [ 'Math.floor' ]让它知道这个函数不会产生任何副作用,在这种情况下整个语句将被丢弃

So the option you're looking for is pure_funcs: [ 'console.log' ] 所以你要找的选项是pure_funcs: [ 'console.log' ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM