mikach / gulp-concat-sourcemap

Concatenate files and generate a source map file.
30 stars 9 forks source link

This does not work with gulp-uglify. #12

Closed rodoabad closed 8 years ago

rodoabad commented 10 years ago

var gulp = require('gulp'),

jshint = require('gulp-jshint'),
concat = require('gulp-concat-sourcemap'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename');

gulp.task('jquery', function() { return gulp.src('src/*.js') .pipe(concat('jquery.min.js', { sourcesContent: true })) .pipe(uglify()) .pipe(gulp.dest('dst')) });

Todd-Werelius commented 10 years ago

Without commenting on the line numbers being wrong from the other reported issues you can get past this by filtering the stream after concat emit's ( it outputs 2 ) by using gulp-filter, you would also have to add a footer yourself to the gulp output for the source map, something like this

var gulp             = require('gulp');
var concat          = require('gulp-concat-sourcemap');
var uglify            = require('gulp-uglify');
var streamFilter  = require('gulp-filter');
var footer            = require('gulp-footer');

gulp.task('named',function(){ 
  var extractJS = streamFilter('output.min.js');
  gulp.src('**/*.js')
    .pipe( concat( 'output.min.js') )
    .pipe(gulp.dest('.')                        // Save both files ( .js and .js.map ) 
    .pipe(extractJS)                            // Filter out the .js.map 
    .pipe(uglify())                               
    .pipe(footer('//# sourceMappingURL='+ 'output.min.js.map')) // Add an anotation
    .pipe(gulp.dest('.'); // Save the .js ( overwrites above save ) 
}

This is just a work around but it got me past the problem, there may be better ways to do this