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?
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']);
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.
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';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With