Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uglify Minify and generate source map with Gulp

Can someone explain how to uglify, then concat and finally generate a source map using gulp? I cannot seem to get it working. I am not seeing anything in the API's about this but seems to me that it should be supported. The point is to generate the source map and have the source files be used when setting breakpoints. I have tried putting the concat first in the following code but when I do that the breakpoints do not work in chrome browser.

I am using
concat = require('gulp-concat'), and uglify = require('gulp-uglify').

gulp.src(['src/app.js', 'src/**/*.js'])
    .pipe(sourcemaps.init())
    .pipe(uglify({
        compress: {
            negate_iife: false
        }
    }))
    .pipe(concat("app.concat.js"))
    .pipe(rename('app.min.js'))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('public/js'));
like image 250
Subtubes Avatar asked Nov 12 '14 11:11

Subtubes


1 Answers

Moving concat before uglify seems to make it work.

gulp.src(['src/app.js', 'src/**/*.js'])
    .pipe(sourcemaps.init())
    .pipe(concat('app.concat.js'))
    .pipe(uglify({
        compress: {
            negate_iife: false
        }
    }))
    .pipe(rename('app.min.js'))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('public/js'));
like image 182
Heikki Avatar answered Sep 29 '22 22:09

Heikki