学无先后,达者为师

网站首页 编程语言 正文

如何在vs-code 中进行debugger调试

作者:渔倒到 更新时间: 2022-04-23 编程语言

链接
首先安装 vs-code 插件
在这里插入图片描述
接下来配置vs-code
我使用的vue-cli3构建的项目因此设置并更新 vue.config.js 内的 devtool property:

module.exports = {
  configureWebpack: {
    devtool: 'source-map'
  }
}

再之后
点击在 Activity Bar 里的 Debugger 图标来到 Debug 视图,然后点击那个齿轮图标来配置一个 launch.json 的文件,选择 Chrome/Firefox:Launch 环境。然后将生成的 launch.json 的内容替换成为相应的配置:
在这里插入图片描述

json文件如下:

{
    "version": "0.2.0",
    "configurations": [
      {
        "type": "chrome",
        "request": "launch",
        "name": "vuejs: chrome",
        "url": "http://localhost:8080",
        "webRoot": "${workspaceFolder}/src",
        "breakOnLoad": true,
        "sourceMapPathOverrides": {
          "webpack:///src/*": "${webRoot}/*"
        }
      },
      {
        "type": "firefox",
        "request": "launch",
        "name": "vuejs: firefox",
        "url": "http://localhost:8080",
        "webRoot": "${workspaceFolder}/src",
        "pathMappings": [{ "url": "webpack:///src/", "path": "${webRoot}/" }]
      }
    ]
  }

最后在需要调试的地方加 上debugger 就可以了

原文链接:https://blog.csdn.net/weixin_38500689/article/details/113383758

栏目分类
最近更新