I have to make 2 steps in gulp:
- Make a .css file form less
- Minify generated css files
This is my gulpfile:
var gulp = require('gulp'),
watch = require("gulp-watch"),
less = require('gulp-less'),
cssmin = require('gulp-cssmin'),
rename = require('gulp-rename');
gulp.task('watch-less', function () {
watch({glob: './*.less'}, function (files) { // watch any changes on coffee files
gulp.start('compile-less'); // run the compile task
});
watch({
glob: ['./*.css', '!./*.min.css']
}, function(files) {
gulp.start('minify-css'); // run the compile task
});
});
gulp.task('compile-less', function () {
gulp.src('./*.less') // path to your file
.pipe(less().on('error', function(err) {
console.log(err);
}))
.pipe(gulp.dest('./'));
});
gulp.task('minify-css', function() {
gulp.src([
'./*.css',
'!./*.min.css'
])
.pipe(cssmin().on('error', function(err) {
console.log(err);
}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./'));
})
gulp.task('default', ['watch-less']);
When i start it only first step is done. Help me please.
This is the way I did it with sass. Kind of the same with less.
The difference with the previous answers is that I wanted one more step:
So the structure would be like this:
Added a new answer in case someone want the same thing as me.
You should keep in mind that with
gulp
you could simply chain operations on aglob
pattern.Don't really sure why you need
gulp.watch
when you can use the built-in watcher, this plugin is useful on tricky situations and that's don't seems be the case here, but you can stick with it if you really want to.Don't forget to
return
your stream sogulp
knows when a task is finished.I also generally wrap all my
watchers
inside onewatch task
, not need to separate them.To me, your gulpfile should look like this:
There is no needing after time, convinient solution for me was:
Best of both worlds might be to add the gulp.watch to the default gulp.task and if you require browser-sync it will reload when you make any changes to the folders being watched as shown below: