ColemanGariety / gulp-nodemon

gulp + nodemon + convenience
526 stars 76 forks source link

Using Gulp nodemon with the VSCode inspector. #148

Open anxious-coder-lhs opened 6 years ago

anxious-coder-lhs commented 6 years ago

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 ?

techsin commented 6 years ago

same problem

roblourens commented 5 years ago

You can set a port like exec: 'node --inspect=9229',, then set the same port in your launch config: "port": 9229