如何在visual studio代码launch.json文件中运行npm脚本

Joh*_*son 4 javascript node.js npm visual-studio-code

我正在尝试在 Visual Studio 代码的 launch.json 文件中运行以下 npm 脚本:

nodemon src/shim-host/index.js --exec babel-node --babel-preset-es2015

到目前为止我在我的launch.json文件中的尝试:

"program": "nodemon src/shim-host/index.js --exec babel-node --babel-preset-es2015",

但是,我收到错误 "Attribute 'program' is not absolute'"

有人可以帮忙吗?

提前致谢!

小智 5

program 属性是你的代码,nodemon 应该是 runtimeExecutable。

Visual Studio Code 文档中的示例:

{
    "name": "Launch server.js via nodemon",
    "type": "node",
    "request": "launch",
    "cwd": "${workspaceRoot}",
    "runtimeExecutable": "nodemon",
    "runtimeArgs": [
        "--debug=5858"
    ],
    "program": "${workspaceRoot}/server.js",
    "restart": true,
    "port": 5858,
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen"
}
Run Code Online (Sandbox Code Playgroud)