Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging variables not working with gulp sourcemaps + uglify

I have the following gulp task for bundling javascript:

gulp.task('js', function () {
    return gulp.src(paths.js)
        .pipe(sourcemaps.init())
        .pipe(uglify())
        .pipe(concat('bundle.min.js'))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('dist'));
});

When I run this in the Chrome dev tools, sourcemaps are found and breakpoints work, but variables can't be debugged.

Take this example chunk of angular code:

iarApp.config(['$animateProvider', function ($animateProvider) {
    $animateProvider.classNameFilter(/angular-animate/);
}]);

If I add a breakpoint to see the value of $animateProvider, I get the following:

enter image description here

But if I turn off variable mangling in Uglify:

.pipe(uglify({ mangle: false }))

Then it works:

enter image description here

So it seems that the gulp-sourcemaps plugin can't follow up variables after Uglify mangles the names.

Can anyone else get the same issue and/or know a solution?

like image 552
Fernando Neira Avatar asked Oct 18 '22 21:10

Fernando Neira


1 Answers

Turns out this is just not possible currently, since this is not part of the specification for source maps.

There are some proposals to add this feature, so we will have to wait until the spec and implementations are updated.

like image 171
Fernando Neira Avatar answered Oct 23 '22 11:10

Fernando Neira