问题
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