我有一个 NodeJS 项目,我可以使用 yarn start
命令从命令行开始。我的 gói.json
看起来类似于:
{
"name": "projectname",
"version": "0.0.1",
"description": "",
"author": "My Name",
"license": "",
"tập lệnh": {
"start": "yarn dev",
"dev": "yarn stop && pm2 start pm2-dev.yaml && webpack-dev-server --progress",
"prod": "yarn stop && yarn build && pm2 start pm2-prod.yaml",
"build": "rimraf dist lib && babel src -d lib --ignore test.js && cross-env NODE_ENV=production webpack -p --progress",
"stop": "rimraf logs/* && pm2 delete all || true"
},
"phụ thuộc": {
"body-parser": "~1.16.0",
"ejs": "2.5.5",
"express": "^4.14.1",
"pg": "^6.1.2",
"react": "^15.4.2",
"redux": "^3.6.0",
},
"devDependencies": {
"babel-cli": "^6.22.2",
"cross-env": "^3.1.4",
"eslint": "^3.13.0",
"pm2": "^2.3.0",
"redux-mock-store": "^1.2.2",
"rimraf": "^2.5.4",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.2.1"
}
}
我正在尝试使用 Visual Studio Code 在 Debug模式下启动这个项目,但几乎没有运气。我在 VS Code launch.json
文件中定义了我的启动配置,如下所示:
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Di chuột để xem mô tả về các thuộc tính hiện có.
// Để biết thêm thông tin, hãy truy cập: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"cấu hình": [
{
"type": "node",
"request": "launch",
"name": "yarn",
"runtimeExecutable": "yarn",
"runtimeArgs": [
"start"
],
"port": 5858,
"cwd": "${workspaceRoot}",
"timeout": 10000
}
]
}
这个配置的问题是它通常会超时,因为 webpack-dev-server
构建时间超过 10 秒。我可以在我的配置中增加 thời gian chờ
,但我注意到 VS Code 结果显示消息 Cannot connect to runtime process (timeout after 30000 ms).
最终,所以我假设这不是一个好的解决方案。此外,这种配置会忽略我的断点,这告诉我我肯定在这里做错了。
这是我第一次尝试 Visual Studio Code,我通常不使用 NodeJS,但我得到了这个项目,其中所有这些脚本在 gói.json
中已经定义,所以我试图采用它,因此对如何正确运行它感到困惑。
Visual Studio Code 是否可以运行这样的项目并具有完整的调试功能?如果可以,我应该如何配置我的启动脚本?
我最终在 launch.json
中有以下配置:
{
"type": "node",
"request": "launch",
"name": "Launch via Yarn",
"runtimeExecutable": "yarn",
"cwd": "${workspaceFolder}",
"runtimeArgs": ["start:debug"],
"port": 5858
}
cũng như gói.json
nội bộ scripts
属性中的以下条目:
"start:debug": "node --inspect-brk=5858 ./server/index.js",
如果您的 package.json 中有任何 prestart:debug
脚本,您可以包含一个 thời gian chờ
键(默认为 10000)并增加它的值
code> 这可能会导致实际 Node 应用程序的启动延迟。
Tôi là một lập trình viên xuất sắc, rất giỏi!