visual studio code 调试 npm 脚本

假如原来 package.json 里有个脚本 "prod": "node ./start.js", 为了在调试状态运行这个脚本,在 package.json 中新建一个脚本 "debug": "node --inspect-brk=9229 ./start.js",这里的 --inspect-brk=9229 会让进程启动后在 9229 端口监听(这句话不确定准确性,我现在是这样认为的)。然后点左边的 debug 图标,新建一个 configuration 如下

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch via NPM",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "run-script",
                "debug"
            ],
            "port": 9229
        },
        
        
    ]
}

点绿色的运行箭头,vs code 会在 debug 状态下运行,设置断点,开始调试。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容