Uglify JS - 仅删除 console.log
Uglify JS - remove only console.log
我有一个关于 Uglify JS
模块的问题,在 webpack 插件的用例中。
我的代码库有几个 console.log
语句围绕代码进行本地调试,它只会在开发模式下打印出来,但它们仍在代码库中占用 space 而我没有他们在生产中构建了什么但是,我想保持我的 console.error
和 console.warn
不变。
我知道 Uglify JS
有关键 drop_console
标志,但这会杀死所有控制台输出,我仍然希望我的控制台中出现警告和错误。
这个问题的原因是我有一个自定义错误处理程序而不是将错误发送到 Sentry,我想在错误发生时在控制台中读取错误,所以我使用错误和警告控制台输出。
来自docs:
drop_console
(default: false
) -- Pass true
to discard calls to console.*
functions. 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.
...
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: [ 'console.log' ]
我有一个关于 Uglify JS
模块的问题,在 webpack 插件的用例中。
我的代码库有几个 console.log
语句围绕代码进行本地调试,它只会在开发模式下打印出来,但它们仍在代码库中占用 space 而我没有他们在生产中构建了什么但是,我想保持我的 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' ]