Javascript 如何在 Webpack 中启用调试模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34142643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I enable debug mode in Webpack?
提问by Justin
I'm trying to utilize the bypassOnDebug
option in image-loader, which means I need to put webpack in "debug mode" (according to the image-loader docs).
我正在尝试使用bypassOnDebug
image-loader 中的选项,这意味着我需要将 webpack 置于“调试模式”(根据 image-loader 文档)。
Is it automatically in debug mode when using the dev server, or do I need to specify that in the webpack config?
使用开发服务器时是否自动处于调试模式,还是需要在 webpack 配置中指定?
If I need to specify it could you please provide a code sample?
如果我需要指定它,你能提供一个代码示例吗?
回答by davnicwil
Webpack 2 & 3
网络包 2 和 3
The debug
property on the top-level configuration is not only deprecated, but invalid.
在debug
对顶级配置属性不仅过时,但无效。
Instead, you have to configure it on a per-loader level, as described by this incredibly friendly error message that displays when you run with the now-invalid debug
top-level property set:
相反,您必须在每个加载器级别上配置它,如使用现在无效的debug
顶级属性集运行时显示的这条非常友好的错误消息所述:
The 'debug' property was removed in webpack 2.
Loaders should be updated to allow passing this option
via loader options in module.rules.
Until loaders are updated one can use the LoaderOptionsPlugin
to switch loaders into debug mode:
plugins: [
new webpack.LoaderOptionsPlugin({
debug: true
})
]
The docs also have similar information.
Note
笔记
I found that updating all my loaders to latest and then trying them one by one to see if they accept a debug
option was a bit heavyweight, considering that I only wanted to set them either all true or all false depending on the config.
我发现将我所有的加载器更新到最新,然后一个一个地尝试它们以查看它们是否接受一个debug
选项有点重量级,考虑到我只想根据配置将它们设置为全部为真或全部为假。
If this is your situation, I can confirm that using webpack.LoaderOptionsPlugin
is the simplest way. It just works, for all loaders old and new.
如果这是您的情况,我可以确认使用webpack.LoaderOptionsPlugin
是最简单的方法。它适用于所有新旧装载机。