你的 package.json 应该有以下部分
"scripts": {
"ng": "ng",
"start": "ng serve --delete-output-path=false",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"}
这些是您要使用的 ng 脚本。从 VS Code 任务中调用它们
只需编辑您的 tasks.json 以包含
{
"taskName": "serve",
"command": "npm start",
"type": "shell",
"problemMatcher": "$tsc"
},
{
"taskName": "open -- -o",
"command": "npm start",
"type": "shell",
"problemMatcher": "$tsc"
},
{
"taskName": "lint",
"command": "npm run lint",
"type": "shell",
"problemMatcher": "$tsc"
},
{
"taskName": "e2e",
"command": "npm run e2e",
"type": "shell",
"problemMatcher": "$tsc"
}
除了调试 Angular,您还可以将以下内容添加到 launch.json
{ "name": "npm start",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200/#",
"webRoot": "${workspaceRoot}"
},
{
"name": "ng test",
"type": "chrome",
"request": "launch",
"url": "http://localhost:9876/debug.html",
"webRoot": "${workspaceRoot}"
},
{
"name": "ng e2e",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/protractor/bin/protractor",
"protocol": "inspector",
"args": ["${workspaceRoot}/protractor.conf.js"]
}