Cocos Creator 2.1.0版本
一、 安装 Debugger for Chrome 插件
二、 配置 launch.json

{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "1.0.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"url": "http://localhost:7456/",
"webRoot": "${workspaceFolder}/temp/quick-scripts/assets/Script",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"url": "http://localhost:7456/",
"webRoot": "${workspaceFolder}/temp/quick-scripts/assets/Script",
"sourceMaps": true,
"sourceMaps": true,
"trace": "verbose",
"runtimeArgs": [
"--auto-open-devtools-for-tabs"
],
"runtimeArgs": [
"--auto-open-devtools-for-tabs"
],
"userDataDir": "${workspaceRoot}/.vscode/chrome",
"pathMapping": {
"/preview-scripts/assets": "${workspaceRoot}/temp/quick-scripts/assets",
"/": "${workspaceRoot}"
},
"preLaunchTask": "mycompile"
}
]
}
三、配置默认生成任务 tasks.json


{
"version": "2.0.0",
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"tasks": [
{
"type": "shell",
"label": "mycompile",
"command": "curl",
"args": [
"http://localhost:7456/update-db"
],
"isBackground": false,
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": true
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
四、 下断点然后 F5 调试
调试时会先执行任务 mycompile 通知开着的Creator编译代码

存在的问题:
步骤中配置launch.json中的"url": "http://localhost:7456/"
,通过Creator预览生成url,多开时端口不一样。
调试时Creator必须开着
喜欢在Chrome中调试的忽喷!
把上述launch.json和tasks.json拷贝到安装路径
\resources\utils\vscode-extension\debugger
就可以更新默认的模板,然后可以从Creator菜单中更新工程配置