E
E
evil0o2016-11-08 18:01:06
gulp.js
evil0o, 2016-11-08 18:01:06

How to compress, minify and add sourcemaps in gulp?

Writing

var gulp = require('gulp')
var concat = require('gulp-concat');
var cleanCSS = require('gulp-clean-css');
var sourcemaps = require('gulp-sourcemaps');
var concatCss = require('gulp-concat-css');
gulp.task('minify-css', function() {
    return gulp.src('./css/*.css')
        .pipe(sourcemaps.init())
        .pipe(cleanCSS())
        .pipe(sourcemaps.write())
        .pipe(concatCss('all.css'))
        .pipe(gulp.dest('dist'));
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SagePtr, 2016-11-08
@SagePtr

I suspect that sourcemaps.write needs to be done after the concatenation so that they are generated for the final concatenated file, and not for intermediate

V
Vladimir Buchatsky, 2016-11-09
@Nemisidis

Yes, just rearrange it and preferably write where to unload it .pipe(sourcemaps.write('/name')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question