Remove Source Mapping with Gulp
Asked Answered
P

3

7

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.

Parasitic answered 14/9, 2015 at 14:15 Comment(0)
C
5

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.

Caitiff answered 14/9, 2015 at 15:6 Comment(5)
Works very well! I'd tried this but I missed the '/dev/null'.Gynaecomastia
in my system (osx) this creates an actual directory in the source folder called 'dev', and another one called 'null' within it.Minded
I'm surprised that doesn't happen on every system. Robert McKee and @max-bündchen on your system does gulp treat the 'null' as a special non-destination, even despite the quotation marks?Christachristabel
@Christachristabel Not really. /dev/null is a special device that throws away everything written to it. DOS/Windows has a similar device NUL: or \\.\NUL. Not sure why it is creating a folder under your source tree when it is an absolute directory name (permissions issue?), but I'm fairly confident that osx has /dev/null as well.Caitiff
Ah that's what I get for not testing. I missed the initial / and don't know my nixes well enough. I see that OSX does indeed have /dev/null. Still haven't tested but I would expect it to workChristachristabel
M
1

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));
});
Minded answered 12/9, 2016 at 17:14 Comment(0)
Q
0

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

Quiteris answered 9/4, 2021 at 8:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.