How do I generate a sourcemap with babel using this directory structure?

廉价感情. 提交于 2019-12-11 12:13:22

问题


gulp.task('build:server:js', function(){
  return gulp.src("server/**/*.js")
    .pipe(sourcemaps.init())
    .pipe(babel({
      "presets": ["es2015", "react", "stage-0"]
    }))
    .pipe(sourcemaps.write('.', {
      includeContent: false,
      sourceRoot: function(file) {
        var from = file.path;
        var to = path.resolve(__dirname+'/../server');
        var dest = path.relative(from, to) + '/../server';

        console.log("from %s\nto: %s\ndest: %s\n", from, to, dest);
        return dest;
      }
    }))
    .pipe(gulp.dest("dist/server/"));
});

gulp tasks are in ./tasks folder, not ./ -- the build is generated in ./dist folder and should point back to ./path/to/src.js.

The dist folder has same structure as root project folder. (ie: ./server/core/routes.js for example ends up in ./dist/server/core/routes.js when transpiled along with the .maps file.

来源:https://stackoverflow.com/questions/33820076/how-do-i-generate-a-sourcemap-with-babel-using-this-directory-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!