This guide will walk you through setting up VSCode with Chrome for debugging Vue.js projects, covering source map configuration and launch settings for differant project structures.
Enabling Webpack Source Maps
First, create a vue.config.js file in your project root to enable webpack source maps:
module.exports = {
configureWebpack: {
devtool: 'source-map'
}
}
Next, navigate to the Run and Debug panel in VSCode and create a launch.json configuration file. The specific settings will depend on your project's src directory location.
Project Structure: src at Root Directory
For projects with the following structure: vue-project/src
Your .vscode/launch.json should include:
- Specify the project's development port: "url": "http://localhost:5173"
- Define the src directory location: "webRoot": "${workspaceFolder}/src"
- Enable source maps: "sourceMaps": true
- Set trace to true for detailed debugging logs: "trace": true
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:5173",
"webRoot": "${workspaceFolder}/src",
"sourceMaps": true,
"trace": true
}
]
}
To begin debugging:
- Start your project normally: npm run dev or npm run serve
- Add breakpoints to your source code at appropriate locations
- Click the Debug button in the VSCode sidebar to launch in debug mode
- A new Chrome browser window will open with debugging capabilities enabled
Project Structure: src in Nested Directory
For projects with the following structure: parent-project/module-vue/src
Your .vscode/launch.json should include:
- Specify the project's development port: "url": "http://localhost:5173"
- Define the src directory location: "webRoot": "${workspaceFolder}/module-vue/src"
- Enable source maps: "sourceMaps": true
- Set trace to true for detailed debugging logs: "trace": true
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:5173",
"webRoot": "${workspaceFolder}/module-vue/src",
"sourceMaps": true,
"trace": true
}
]
}
The debugging process remains the same as in the previous scenario:
- Start your project normally: npm run dev or npm run serve
- Add breakpoints to your source code
- Launch the debugger from VSCode
- Chrome will open with debugging capabilities ready
With these configurations in place, backend developers transitioning to Vue.js can effectively debug their applications using familiar tools and workflows.