Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp.js starts sass task but doesn't finish

Tags:

sass

gulp

My gulpfile.js

var gulp = require('gulp');

// plugins
var sass = require('gulp-sass');
var minifycss = require('gulp-minify-css');

// compile sass
gulp.task('sass', function() {
    return gulp.src('static/css/scss/main.scss')
        .pipe(sass())
        .pipe(minifycss())
        .pipe(gulp.dest('/static/css/main.css'));
});

gulp.task('watch', function() {
    gulp.watch('static/css/scss/*.scss', ['sass']);
})

gulp.task('default', ['watch']);

When I run gulp I get the following output:

[gulp] Using gulpfile /var/www/example/gulpfile.js
[gulp] Starting 'watch'...
[gulp] Finished 'watch' after 21 ms
[gulp] Starting 'default'...
[gulp] Finished 'default' after 23 μs

Then when I save my main.scss file it outputs:

[gulp] Starting 'sass'...

At which point it just hangs and never finishes. What am I doing wrong?

like image 370
xylar Avatar asked May 10 '14 18:05

xylar


3 Answers

The return inside the sass task seemed to break it, updated my gulpfile.js to following to get it working:

var gulp = require('gulp');

// plugins
var sass = require('gulp-sass');
var minifycss = require('gulp-minify-css');

// compile sass
gulp.task('sass', function() {
    gulp.src('static/css/scss/main.scss')
        .pipe(sass())
        .pipe(minifycss())
        .pipe(gulp.dest('/static/css'));
});

gulp.task('watch', function() {
    gulp.watch('static/css/scss/*.scss', ['sass']);
})

gulp.task('default', ['watch']);
like image 84
xylar Avatar answered Nov 09 '22 02:11

xylar


For anyone else who has this issue, I managed to fix this by removing circular imports.

For example...

Before:

file1.scss
@import 'file2';

file2.scss
@import 'file1';

After:

file1.scss
<removed import>

file2.scss
@import 'file1';

I didn't actually need the circular dependency, I was just copying/pasting dependencies to the tops of all my scss files.Note that if your files actually need to import one another you'd either need to refactor your files in such a way that you avoid circular dependencies.

like image 36
Hanna Avatar answered Nov 09 '22 02:11

Hanna


The reason my sass compilation was not working and the gulp process was hanging and pinging my processor was that I had an old reference in my .scss file but I had removed the file. There was never any output that complained - this was hard to track down - I got lucky.

@import 'file-that-has-been-removed-but-still-referenced';

like image 21
somedirection Avatar answered Nov 09 '22 00:11

somedirection