我有一个关于 webpack 插件用例中的 Uglify JS
模块的问题。
我的代码库在代码周围有几个用于本地调试目的的 console.log
语句,它只会在开发模式下打印出来,但它们仍然占用代码库中的空间,我不知道什么它们在生产版本中,但是,我想保持我的 console.error
和 console.warn
不变。
我知道 Uglify JS
有关键的 drop_console
标志,但这会杀死所有控制台输出,但我仍然希望控制台中出现警告和错误。
这个问题的原因是我有一个自定义错误处理程序,而不是向 Sentry 发送错误,并且我想在发生错误时在控制台中读取错误,因此我使用错误和警告控制台输出。
最佳答案
来自docs :
drop_console
(default:false
) -- Passtrue
to discard calls toconsole.*
functions. If you wish to drop a specific function call such asconsole.info
and/or retain side effects from function arguments after dropping the function call then usepure_funcs
instead....
pure_funcs
(default:null
) -- [...] You can passpure_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: [ 'console.log' ]
关于javascript - Uglify JS - 仅删除 console.log,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52815146/