2

I'm having a strange problem with Gulp. Here is my Gulp file:

var gulp = require('gulp');
var autoprefixer = require('gulp-autoprefixer');
var notify = require('gulp-notify');
var sass = require('gulp-ruby-sass');

gulp.task('default', function() {
    gulp.run('main');

    gulp.watch('sass/*.scss', function() {
        gulp.run('main');
    })
});


gulp.task('main', function() {
    return gulp.src('sass/**/*.scss')
        .pipe(sass())
        .on('error', notify.onError(function(error) { return 'Error: ' + error.message; }))
        // .pipe(autoprefixer('last 10 version'))
        .pipe(gulp.dest('./css'))
        .pipe(notify({ message: 'Your SASS has been auto-prefixed and minified.'}))
    ;
});

The script runs correctly the first time. But on second and subsequent runs of the same script (without Gulp having stopped running), it puts it in the SASS directory as a subitem of the .SCSS file. Any idea why this is happening. I'm not sure how to even debug.

sehummel
  • 5,476
  • 24
  • 90
  • 137
  • Please check that you're using the latest stable gulp version and show us the file structure of your project before and after gulp tasks. I don't understand what you mean by 'it puts it in the SASS directory as a subitem of the .SCSS file', I'm using your gulpfile and for me it works as expected. – Alex Guerrero May 24 '14 at 04:54

2 Answers2

1

Try the following code.

It uses the correct syntax for gulp, replacing gulp.run() with the supported function arguments.

var gulp = require('gulp');
var autoprefixer = require('gulp-autoprefixer');
var notify = require('gulp-notify');
var sass = require('gulp-ruby-sass');




gulp.task('main', function() {
  return gulp.src('./sass/**/*.scss')
    .pipe(sass())
    .on('error', notify.onError(function(error) { return 'Error: ' + error.message; }))
    .pipe(gulp.dest('./css'))
    .pipe(notify({ message: 'Your SASS has been auto-prefixed and minified.'}));
});

gulp.watch('sass/*.scss', ['main']);
gulp.task('default', ['main']);
SteveLacy
  • 4,150
  • 2
  • 23
  • 30
  • Nope. It's still saving the file in the SASS directory. And I'm still getting the error about `gulp.run()` being deprecated. – sehummel May 17 '14 at 10:52
  • Please update your post with your Entire gulpfile. You can not be getting the gulp.run error unless you have other tasks defined in your gulpfile which you did not list here. – SteveLacy May 17 '14 at 15:51
  • That is my entire Gulp file. – sehummel May 17 '14 at 21:31
  • I replaced my file with yours and am still getting the error. – sehummel May 17 '14 at 21:31
  • What is your ruby sass version? Have you tried using `gulp-sass`? – SteveLacy May 18 '14 at 15:38
  • Yes. The issue seems to be the destination folder. – sehummel May 18 '14 at 20:25
  • 1
    did this get resolved? I am having the same problem. It seems that whatever your gulp.src folder is this gets added to destination, ie if gulp.src('test/*.scss') and gulp.dest('./css'), then the file will actually go into css/test, the source folder gets appended to destination. – dan Apr 20 '15 at 04:51
1

Found the answer, the gulp.dest keeps the folder structure of gulp.src, to override you can set the base property of the src, this will exclude whatever folder the base is set to

example gulp.src('./sass/' + '**/*.scss', {base: 'sass'}) this now excludes sass from the destination, no longer appending sass to your gulp.dest

See and this look at gulp.src

Community
  • 1
  • 1
dan
  • 2,857
  • 6
  • 34
  • 60