Debug compiled ES6 nodejs app in WebStorm

前端 未结 5 1976
灰色年华
灰色年华 2020-12-31 05:00

I want to debug a node app that runs from babel compiled ES6 files. I have my ES6 source in an src folder and the babel ES5 equivalent in a b

5条回答
  •  失恋的感觉
    2020-12-31 05:35

    @mockaroodev solution will work only if you have a flat hierarchy in source. If you have sources in different subpaths, an absolute path (from the domain root) pointing to the source file root is recommended for sourceRoot option.

    Updated gulp babel task:

    var gulp = require('gulp'),
        sourcemaps = require('gulp-sourcemaps'),
        babel = require('gulp-babel'),
        gutil = require('gulp-util'),
        path = require('path');
    
    // Compile ES6 to ES5
    gulp.task("babel", function () {
        return gulp.src('**/*.js')
            .pipe(sourcemaps.init())
            .pipe(babel())
            .on('error', gutil.log)
            .pipe(sourcemaps.write('.', {
                includeContent: false,
                sourceRoot: function(file) {
                    return path.relative(file.path, __dirname);
                }
            }))
            .pipe(gulp.dest('dist'));
    });
    

提交回复
热议问题