4

For web projects not using npm or task runners, can you you some how get the debugger for Chrome extension to start a server before it starts debugging? I'm using the Live server debugging extension and it would be nice to be able to start the debugging with just one click.

Can I use the "preLaunchTask" property somehow for instance?

Magistern
  • 143

2 Answers2

3

I was able to get this running using preLaunchTask. Now both the debugger and the live server start with one click. Here are my .vscode folder config files.

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "port": 9222,
            "request": "launch",
            "type": "pwa-chrome",
            "url": "http://localhost:5500",
            "webRoot": "${workspaceFolder}",
            "preLaunchTask": "StartServer",
            "postDebugTask": "StopServer"
        }
    ]
}

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "StartServer",
            "type": "process",
            "command": "${input:startServer}"
        },
        {
            "label": "StopServer",
            "type": "process",
            "command": "${input:stopServer}"
        }
    ],
    "inputs": [
        {
            "id": "startServer",
            "type": "command",
            "command": "extension.liveServer.goOnline"
        },
        {
            "id": "stopServer",
            "type": "command",
            "command": "extension.liveServer.goOffline"
        }
    ]
}

settings.json (workspace settings)

{
    "liveServer.settings.ChromeDebuggingAttachment": true,
    "liveServer.settings.CustomBrowser": "chrome",
    "liveServer.settings.host": "localhost",
    "liveServer.settings.NoBrowser": true
}
1

You want "compounds" as a top level property in your launch.json. Like so:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Server Debug",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}/server/server.js",
            "cwd": "${workspaceRoot}",
            "protocol": "inspector",
            "skipFiles": [
                "<node_internals>/**/*.js",
                "${workspaceRoot}/node_modules/**/*.js"
            ]
        },
        {
            "name": "Client Debug",
            "type": "chrome",
            "request": "launch",
            "url": "http://localhost:3000/",
            "webRoot": "${workspaceFolder}/clientSrc",
            "skipFiles": [
                "${workspaceFolder}/node_modules/",
            ]
        }
    ],
    "compounds": [
        {
            "name": "Debug Both",
            "configurations": ["Server Debug", "Client Debug"]
        }
    ]
}

You can then combine multiple other runners into one or more "compound runners".