在Visual Studio代码调试中的Express TypeScript Gulp



我正在尝试实现express/typescript/gulp应用程序,它有效,但我仍然无法使用源映射进行调试。

这是我的设置

Gulp File

var gulp = require('gulp'),
    nodemon = require('gulp-nodemon'),
    livereload = require('gulp-livereload'),
    sourcemaps = require('gulp-sourcemaps'),
    gulpPlumber = require('gulp-plumber'),
    merge = require('merge2'),
    ts = require('gulp-typescript');
var tsProject = ts.createProject('tsconfig.json');
gulp.task('typescript', function() {
   console.log('Compiling TypeScript');
    var tsResult = gulp.src(['src/**/*.ts']) 
        .pipe(gulpPlumber())
        .pipe(sourcemaps.init())
        .pipe(tsProject());
    // merge dts & js output streams...
    return merge([
        // type definitions
         tsResult.dts
            .pipe(gulp.dest("./src/")),
          // javascript
        tsResult.js
            //.pipe(sourcemaps.write(writeOptions))
            .pipe(gulp.dest('./src/'))
        ]);

});
gulp.task('serve', ['typescript'], function () {
    gulp.watch('./**/*.ts', ['typescript']);
    livereload.listen();
    nodemon({
        script: './relax',
        ext: 'js',
    }).on('restart', function () {
        setTimeout(function () {
            console.log("reload!");
            livereload.reload();
        }, 500);
    });
});

这是VS代码启动文件:

"configurations": [
    {
        "name": "Launch Program",
        "type": "node2",
        "request": "launch",
        "program": "${workspaceRoot}\relax.js",
        "cwd": "${workspaceRoot}",
        "outFiles": [],
        "sourceMaps": true
    },
    {
        "name": "Attach to Process",
        "type": "node2",
        "request": "attach",
        "address": "localhost",
        "restart": false,
        "sourceMaps": false,
        "localRoot": "${workspaceRoot}",
        "remoteRoot": null,
        "port": 5858
    }
]

完整的代码可以在git回购中找到:https://github.com/michalzak/beanbag

我无法将此过程附加到我的节点服务器上。有任何建议吗?

未使用sourcemap的原因是因为它们不存在。换句话说,您不是在编写/保存生成的Sourcemaps。您可以通过在gulpfile.js中添加这两条行来做到这一点:

return merge([
...
    ])
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('./src/'));

相关内容

  • 没有找到相关文章

最新更新