Search code examples
sassgulpgulp-sassautoprefixer

Gulp ruby-sass and autoprefixer do not get along


I have a styles task in my gulpfile:

gulp.task('styles', function () {
  var sass = require('gulp-ruby-sass');
  var autoprefixer = require('gulp-autoprefixer');
    return gulp.src('app/styles/main.scss')
    .pipe(sass({sourcemap: true, sourcemapPath: '../scss'}))
    .on('error', function (err) { console.log(err.message); })
    .pipe(autoprefixer({
        browsers: ['last 2 versions'],
        cascade: false
    }))
    .pipe(gulp.dest('.tmp/styles'));
});

which generates this in the console:

[14:25:21] Starting 'styles'...
[14:25:21] gulp-ruby-sass: stderr: DEPRECATION WARNING: Passing --sourcemap without a value is    deprecated.
Sourcemaps are now generated by default, so this flag has no effect.
[14:25:21] gulp-ruby-sass: directory
[14:25:25] gulp-ruby-sass: write main.css
  write main.css.map

  events.js:72
    throw er; // Unhandled 'error' event
          ^
  Error: /Users/stevelombardi/Documents/command-central/ccgulp/main.css.map:3:3: Unknown word

IF I comment out the pipe to autoprefixer, no errors, everything compiles. What's the deal here?

Note, I also cannot seem to disable the writing of a sourcemap. I tried all the other settings from the repo page for grunt-ruby-sass and none work.

I can live without autoprefixer, but would love to get it working...


Solution

  • Instead of:

    browsers: ['last 2 versions'],
    

    Try this:

    browsers: ['last 2 version'],
    

    If that doesn't work, I've had better luck with gulp-sass and gulp-sourcemaps.

    // Compile Sass & create sourcemap
    .pipe(sourcemaps.init())
        .pipe(sass())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('css'))
    
    // Autoprefix, load existing sourcemap, create updated sourcemap
    .pipe(sourcemaps.init({loadMaps: true}))
        .pipe(autoprefixer('last 2 version')
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('css'))