VSCode: Automatically run npm script on starting debugging of a web project
·
Answer a question
So here is my VS code launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:4321",
"port": 9222,
"webRoot": "${workspaceFolder}"
}
]
}
What I want is run npm start command right before debugging begins i.e running dev server then launching a Chrome instance and navigating to the provided url.
So, I added the following snippet to the config file and ran the debug:
"cwd": "${workspaceRoot}",
"runtimeExecutable": "npm",
"runtimeArgs": [
"start"
]
but I got the this error:
Attribute runtimeExecutable does not exist ('npm')
Any help?
Answers
Found the solution: I need a preLaunchTask
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome against localhost",
...
// This runs dev server before debugger
"preLaunchTask": "start-dev-server",
}
]
}
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "start-dev-server",
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"owner": "npm",
"background": {
"activeOnStart": true,
"beginsPattern": ".*",
"endsPattern": "Finished.+"
},
"pattern": {
"regexp": "",
}
}
},
]
}
更多推荐
所有评论(0)