简体   繁体   English

如何调试使用 webpack 编译的 npm 模块?

[英]How can I debug an npm module compiled with webpack?

Is there a way to put breakpoints and execute the code step-by-step in the code of an npm module which is compiled with webpack?有没有办法在使用 webpack 编译的 npm 模块的代码中设置断点并逐步执行代码?

The compiled code is not that useful for debugging and when the module is imported locally with npm link , only the compiled code is accessed from an application using the module.编译后的代码对调试没有多大用处,当使用npm link在本地导入模块时,使用该模块的应用程序只能访问编译后的代码。

How to do this in VSCode (or in any other code editor/ide)?如何在 VSCode(或任何其他代码编辑器/ide)中执行此操作?

you can debug that easily in the browser if you add this row to webpack.config file:如果将此行添加到webpack.config文件中,则可以在浏览器中轻松调试:

  devtool: "inline-source-map"

and then run the scripts in dev mode:然后在开发模式下运行脚本:

--mode development

Then, if you set the debugger keyword in your npm package and run that in your main project you will see the full code:然后,如果您在 npm package 中设置debugger关键字并在您的主项目中运行它,您将看到完整的代码:

在此处输入图像描述

I found another very good article about that topic if you want to learn more https://blog.jakoblind.no/debug-webpack-app-browser/如果您想了解更多信息,我发现了另一篇关于该主题的非常好的文章https://blog.jakoblind.no/debug-webpack-app-browser/

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

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