rschmukler / gulp-insert

string mutation library for gulp
MIT License
61 stars 6 forks source link

Sourcemap support? #9

Open psi-4ward opened 9 years ago

psi-4ward commented 9 years ago

Using gulp-insert with https://github.com/floridoo/gulp-sourcemaps shifts the lines:

gulp-task:

gulp.task('app', function() {
  return gulp.src('js/*.js')
    .pipe(sourcemaps.init())
    .pipe(insert.wrap('!function(){ "use strict"; var app; ' + "\n", "\n}();")
    .pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '/'})
    .pipe(gulp.dest('dist'));
})

a JS file

debugger;
var nextline;

Breaks on var nextline caused of the insert-wrap line

efolio commented 9 years ago

This would be very nice!

psi-4ward commented 9 years ago

I looked into the anatomy of sourcemaps, adding support for a appended string should not be complicated but altering the sourcemap for an prepended one results in a complex line-offset movearound.

I replaced gulp-insert with gulp-add

  var s = gulp.src(sources, {base: 'modules'});
  s = s.pipe(add('generated-header.js', header, true));
  s = s.pipe(add('generated-footer.js', footer));
  s = s.pipe(sourcemaps.init());
  s = s.pipe(concat('app.js'));

so concat's sourcemap support handles the stuff for me

Birkenstab commented 6 years ago

The module gulp-header supports source maps. But it can only do a prepend as the name may suggest.