Retaining line numbers

To use babel-node with the VSCode debugger, we also need to enable the retainLines option in Babel, which retains the line numbers between the source code and the built files. If we don't do this, VSCode's debugger would set the breakpoints at the incorrect lines.

However, we only want to retain lines when debugging our code; when we are building our application, we want it to be formatted sensibly. To do this, we can update our .babelrc to apply the retainLines option only when the BABEL_ENV environment variable is set to "debug":

{
"presets": [
["@babel/env", {
"targets": {
"node": "current"
}
}]
],
"env": {
"debug": {
"retainLines": true
}
}
}

Then, open up the launch.json file again and add the following to the Babel Node configuration:

{
"name": "Babel Node",
"type": "node",
...
...
"protocol": "inspector",
"env": {
"BABEL_ENV": "debug"
}
},