Max Bündchen
Max Bündchen

Reputation: 1362

Remove Source Mapping with Gulp

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.

Upvotes: 7

Views: 6814

Answers (3)

Binar Web
Binar Web

Reputation: 943

Being on Windows, none of the response here worked for me.
I have a different approach on the matter, but there is a trade-off: you lose all the comments from the output.

const stripComments = require('gulp-strip-comments')

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

For more info: gulp-strip-comments

Upvotes: 0

Robert McKee
Robert McKee

Reputation: 21487

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.

Upvotes: 5

Mike Furlender
Mike Furlender

Reputation: 4019

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));
});

Upvotes: 1

Related Questions