gulpgulp-sassautoprefixergulp-sourcemapsgulp-autoprefixer

gulp sass sourcemaps and autoprefixer not working


I am unable to get the autoprefixer working with gulp sass. Here is my gulpfile.js:

'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
gulp.task('sass', function () {
  gulp.src('./sass/**/*.scss')
    .pipe(sourcemaps.init())
    .pipe(sass().on('error', sass.logError))
    .pipe(sourcemaps.write())
    .pipe(autoprefixer({ browsers: ['last 2 versions' ]}))
    .pipe(gulp.dest('./css/'));
});
gulp.task('watch', function () {
  gulp.watch('./sass/**/*.scss', ['sass']);
});
gulp.task('default', function () {
  gulp.watch('./sass/**/*.scss', ['sass']);
});

I followed the solution in related question but couldn't get it done. Here is the link : LINK


Solution

  • I was able to achieve the sourcemaps and autoprefix functionality so thought of sharing. Here is my gulpfile.js :

    'use strict';
    var gulp = require('gulp');
    var sass = require('gulp-sass');
    var sourcemaps = require('gulp-sourcemaps');
    var autoprefixer = require('gulp-autoprefixer');
    gulp.task('sass', function () {
      gulp.src('./sass/**/*.scss')
        .pipe(sourcemaps.init())
        .pipe(sass().on('error', sass.logError))
        .pipe(sourcemaps.write())
        .pipe(autoprefixer())
        .pipe(gulp.dest('./css/'));
    });
    gulp.task('watch', function () {
      gulp.watch('./sass/**/*.scss', ['sass']);
    });
    gulp.task('default', function () {
      gulp.watch('./sass/**/*.scss', ['sass']);
    });