Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Source Mapping with Gulp

Tags:

jquery

gulp

bower

I'm using Gulp and Bower to get JQuery into my project. However the jquery.min.cs file has a SourceMappingURL at the end of the precompiled file and I would like to remove this.

Currently my Gulp just copy the original file to the destination like that:

gulp.task('jquery', function () {
    gulp.src(paths.jquerySrc)
        .pipe(gulp.dest(paths.jqueryDest));
});

I found a lot of ways to add source mappings but none to remove. I would like to not recompile all the jquery just for that.

like image 335
Max Bündchen Avatar asked Sep 14 '15 14:09

Max Bündchen


2 Answers

You could try this:

const paths = {
    jquerySrc: './path/to/src/jquery.css',
    jqueryDest: './path/to/dest/'
};

gulp.task('jquery', function () {
    gulp.src(paths.jquerySrc)
        .pipe(sourcemaps.init({loadMaps: true}))
        .pipe(sourcemaps.write('/dev/null', {addComment: false}))
        .pipe(gulp.dest(paths.jqueryDest));
});

You could also try the strip-source-map-loader package. Never used either, but in theory both should work, maybe.

like image 90
Robert McKee Avatar answered Sep 27 '22 23:09

Robert McKee


The gulp-purge-sourcemaps package worked for me. Here's what you would do with your example:

const purgeSourcemaps = require('gulp-purge-sourcemaps');

gulp.task('jquery', function () {
    gulp.src(paths.jquerySrc)
        .pipe(sourcemaps.init({loadMaps: true}))
        .pipe(purgeSourcemaps())
        .pipe(gulp.dest(paths.jqueryDest));
});
like image 23
Mike Furlender Avatar answered Sep 27 '22 22:09

Mike Furlender