0

Here's my gulpfile.js

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

gulp.task('sass', function() {
    return sass('assets/scss/*.scss')
    .on('error', sass.logError)
    .pipe(gulp.dest('assets/css'))
});

The error logging works, for example if I set an undefined variable in my Sass the terminal will show:

[13:31:23] Using gulpfile ~/Development/test/gulpfile.js
[13:31:23] Starting 'sass'...
[13:31:23] error assets/scss/style.scss (Line 3: Undefined variable: "$red".)
[13:31:23] Finished 'sass' after 248 ms

I have included chalk as I would like to change the color of the error in Terminal, but how would I go about doing that? I have tried:

.on('error', chalk.red(sass.logError))

But that doesn't work. Please help!

  • It doesn't work because `chalk.red` is expecting a `string` but you're giving it a `function`. You could reimplement `sass.logError` if you feel like it... – kombucha Oct 06 '15 at 17:45
  • Late to the party, but I'm not actually seeing where you're using Chalk in your first example. If you're at all still facing this issue, could you edit with a complete example? – Qix - MONICA WAS MISTREATED Aug 06 '16 at 05:46

1 Answers1

0

@kombucha is right, you can reimplement sass.logError and use chalk.red inside of that. After checking source code of sass.logError from https://github.com/sindresorhus/gulp-ruby-sass/blob/master/index.js, the result would be like:

var gutil = require('gulp-util');
...
.on('error', function() {
    var message = new gutil.PluginError('gulp-ruby-sass', err);
    console.error(chalk.red(message + '\n'));
    this.emit('end');
})
shaochuancs
  • 15,342
  • 3
  • 54
  • 62