简体   繁体   English

VSCode 源映射显然不起作用

[英]VSCode source map does not work apparently

I was trying to debug a chrome extension on VSCode, and in that attempt I noticed that breakpoint is not working on the scripts (eg background.js);我试图在 VSCode 上调试 chrome 扩展,在尝试中我注意到断点不适用于脚本(例如 background.js); So I googled and I took a look some posts and tried some, and finally I have no idea to identify what's wrong.所以我用谷歌搜索了一些帖子并尝试了一些,最后我不知道出了什么问题。

The .vscode/launch.json on my chrome project我的 chrome 项目上的 .vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome",
            "url": "http://localhost:8291",
            "runtimeArgs": ["--load-extension=${workspaceFolder}"], 
            "runtimeExecutable": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",

            "webRoot": "${workspaceFolder}",
            "breakOnLoad": true,
            "sourceMaps": true,
            "sourceMapPathOverrides": {
                "*": "${webRoot}/*"
            }
        }
    ]
}

Initially I didn't have the webRoot, breakOnLoad, sourceMaps, sourceMapPathOverrides properties but after reading the doc and a post (below the link) I added these.最初我没有 webRoot、breakOnLoad、sourceMaps、sourceMapPathOverrides 属性,但在阅读了文档和帖子(链接下方)之后,我添加了这些属性。

The post I referred: Solve “Breakpoint ignored” with Visual Studio code (vscode 1.19+) Chrome debugger |我提到的帖子: 使用 Visual Studio 代码(vscode 1.19+)解决“断点被忽略”Chrome 调试器 | by Ananto Ghosh | 通过阿南托·戈什 | Frontend Weekly | 前端周刊 | Medium 中等的

Also I noticed that I have the vscode-chrome-debug extension which is deprecated and recommended to be uninstalled, I did uninstall.我还注意到我有一个已弃用并建议卸载的 vscode-chrome-debug 扩展,我确实卸载了。 (So made sure not to happen any further tricky issue) (所以确保不会发生任何进一步的棘手问题)

The file tree on the project:项目上的文件树:

├── .vscode 
├── background.js
├── bookmarklet.js
├── content.js
├── dialog.html
├── dialog.js
└── manifest.json

Now type F5 key to run the project, chrome opened, opening dev tools and navigated to the source tab and checking if there is the project files showing correctly... no there is not any.现在键入 F5 键运行项目,打开 chrome,打开开发工具并导航到源选项卡并检查项目文件是否正确显示......不,没有。 (and so of course breakpoint does not work yet as I could expect) (当然断点还不能像我预期的那样工作)

In my mind (since the SO terms, this is not a question and you don't need to answer):在我看来(因为 SO 条款,这不是一个问题,你不需要回答):

  • What the hell is sourceMaps? sourceMap 到底是什么鬼? Do I need to create that sourceMaps thing manually before F5 or such?我是否需要在 F5 之前手动创建那个 sourceMaps 东西? If so where the heck is the doc?如果是这样,医生到底在哪里?
  • What is the URL localhost thing for? URL localhost 有什么用? I'd like to ensure that just specify that with a port is enough, right?我想确保只指定一个端口就足够了,对吧? Or do I need to launch a server or something before the F5 run?还是我需要在 F5 运行之前启动服务器或其他东西? What in the world is that server thing then.那服务器到底是什么东西。

So, what's wrong with the project/launch.json?那么,project/launch.json 有什么问题呢?

you asked *What the hell is sourceMaps?你问 *sourceMaps 到底是什么? Do I need to create that sourceMaps thing manually before F5 or such?我是否需要在 F5 之前手动创建那个 sourceMaps 东西? If so where the heck is the doc?如果是这样,医生到底在哪里?

The answer to the first.第一个的答案。 Even though JavaScript does need to be compile it usually is.尽管 JavaScript 确实需要编译,但它通常也是如此。 Compilation is the process of removing white space and using other code optimisation other trick to make your JavaScript faster and smaller but this make readability.编译是删除空白并使用其他代码优化其他技巧的过程,以使您的 JavaScript 更快更小,但这会提高可读性。 A sourcemaps does what it sound it map the compiled code to the compiled source. sourcemaps 做它听起来的事情,它将已编译的代码映射到已编译的源代码。

The answer to the 2nd. 2楼的答案。

Yes and no.是和不是。 You do need to make the source map if you are compiling the javascript your self but this is usually done with webpack,esbuild, or what ever compiler you are using.如果您要自己编译 javascript,则确实需要制作源映射,但这通常使用 webpack、esbuild 或您使用的任何编译器来完成。 If the package is compiled for you might have to going look to where you got the script from the should have the compiled version somewhere.如果包是为你编译的,你可能不得不去看看你从哪里得到脚本的地方应该有编译版本。

The answer to your last the doc should be with the compiler you are using.你最后一个文档的答案应该是你正在使用的编译器。

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

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