Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to pick up changes from gulp-watch #110

Open
morioust opened this issue Sep 27, 2015 · 3 comments
Open

Fails to pick up changes from gulp-watch #110

morioust opened this issue Sep 27, 2015 · 3 comments

Comments

@morioust
Copy link

I'm unable to make gulp-compass compile anything coming piped through gulp-watch.

This works:

return gulp.src('app/styles/base.scss')
    .pipe(compass({
      sass: 'app',
      css: '.tmp'
    }));

This doesn't work:

return gulp.src('app/styles/base.scss')
    .pipe(watch('app/styles/base.scss'))
    .pipe(compass({
      sass: 'app',
      css: '.tmp'
    }));

The pipe does produce a vinyl on change (I verified with gulp-debug), but gulp-compass fails to compile them, as soon as I add the watch pipe.

@morioust
Copy link
Author

It seems the issue is in index.js:

return through.obj(collectNames, compile);

The compilation happens only when through calls the flush function. My guess is that since gulp-watch keeps the stream open, it never calls the flush function.

@dancras
Copy link

dancras commented Oct 22, 2015

Here's a solution I'm using. You should be able to do the following:

return gulp.src('app/styles/base.scss')
    .pipe(watch('app/styles/base.scss'))
    .pipe(compassSingleFile({
      sass: 'app',
      css: '.tmp'
    }));
/**
 * Run compass on single sass files as they come down the stream.
 *
 * The gulp-compass plugin collects all files and runs compass on them when the
 * stream is over, but the stream is never over when watching.
 */
function compassSingleFile(config) {

    var source = require('vinyl-source-stream');

    return require('event-stream').map(function(file, callback) {

        var result;

        var stream = source(file.relative)
            .pipe($.compass(config))
            .on('data', function(data) {
                result = data;
            })
            .on('end', function() {
                callback(null, result);
            });

        stream.write(file);
        stream.end();
    });
}

@ghetolay
Copy link

My way was to use both compass watch and gulp-watch. It's not optimal but works.

gulp.src('path_to_scss/*.scss')
     .pipe( compass({
           sass: 'path_to_scss',
           css: './tmp',
           task: 'watch'
    }))
   .pipe( gulp.watch('./tmp/*.css'))
   .pipe( ... );

Since there is no communication possible between compass and gulp (except parsing stdout) we kinda use files to do it.
Compass watch .scss files.
Gulp watch .css file.

So when you modify a .scss file => compass triggered => new css file produced => gulp-watch triggered => file added to stream => wonderful things happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants