dlmanning / gulp-sass

SASS plugin for gulp
MIT License
1.57k stars 381 forks source link

gulp-load-plugins can't not use gulp-sass5 #806

Closed hsiangfeng closed 2 years ago

hsiangfeng commented 3 years ago

I initially used const $ = require('gulp-load-plugins')(); run gulp-sass

const $ = require('gulp-load-plugins')();
$.sass.compiler = require('sass');

gulp.task('sass', function () {
    return gulp.src('./source/scss/**/*.scss')
        .pipe($.plumber())
        .pipe($.sass().on('error', $.sass.logError))
        .pipe($.postcss([autoprefixer()]))
        .pipe(gulp.dest('./public/css'));
});

now gulp-sass5 is not working.

Error in plugin "gulp-sass"
Message:

gulp-sass 5 does not have a default Sass compiler; please set one yourself.
Both the `sass` and `node-sass` packages are permitted.
For example, in your gulpfile:

  var sass = require('gulp-sass')(require('sass'));

So can I only use the following methods?

const $ = require('gulp-load-plugins')();
var sass = require('gulp-sass')(require('sass'));

gulp.task('sass', function () {
    return gulp.src('./source/scss/**/*.scss')
        .pipe($.plumber())
        .pipe(sass().on('error', sass.logError))
        .pipe($.postcss([autoprefixer()]))
        .pipe(gulp.dest('./public/css'));
});

My question is can gulp-load-plugins gulp-sass5.

circa1983 commented 3 years ago

Following gulp-load-plugins documentation on postRequireTransforms, I added the following to get it working so sass can still be called with $.sass().

const $ = require('gulp-load-plugins')({
  postRequireTransforms: {
    sass: function(sass) {
      return sass(require('sass'));
    }
  }
});
XhmikosR commented 2 years ago

@xzyfer this can be closed too.