3

I am trying to figure out the VSCode launch configuration for launching a gulp task in the inspect mode. The gulp task internally transpiles the code and runs the process via gulp-nodemon. Example is given as below:

VSCode Launch script:

{
  "type": "node",
  "request": "launch",
  "name": "Gulp App debug",
  "program": "${workspaceRoot}\\node_modules\\gulp\\bin\\gulp.js",
  "args": [
    "serve:dev"
  ],
  "sourceMaps": true,
  "outputCapture": "std"
}

Gulp Task:

gulp.task("serve:dev", ["release"], () => {
  const through = require("through2");
  const nodemon = require("gulp-nodemon");
  const nodemonStream = nodemon({
    script: "dist/src/app.js",
    ext: "",
    exec: 'node --inspect',
    // nodeArgs: ['--inspect'],
    watch: "none", // Disabled, will be triggered externally.
    env: Object.assign(process.env, {
      LOG_LEVEL: "debug",
      EXEC_MODE: "dev",
      NODE_PATH: "dist/src"
    })
  });

  const watchSrc = watch("./src/**/*", vinyl => {
    return compileSourcesStream(
      gulp.src(vinyl.path),
      gulp.dest("dist/src")
    ).pipe(
      through.obj(function(chunk, enc, cb) {
        nodemonStream.emit("restart");
        cb(null, chunk);
      })
    );
  });

In the above configuration, the VSCode launches the gulp task with the inspect mode binding to a random port. However the gulp task itself runs the nodemon with the inspect mode pointing to a different new random port. This leads to VSCode unable to track the launched process.

Any suggestion on the above setup ?

Tomasz Mularczyk
  • 34,501
  • 19
  • 112
  • 166
Love Hasija
  • 2,528
  • 2
  • 27
  • 26

0 Answers0