There are a few .less files in less folder like style.less
(it's main working file), colors.less
, fonts.less
, mixins.less
and so on.
I use @import to add additional files in main style.less
file.
@import "colors.less";
@import "fonts.less";
@import "mixins.less";
It's my gulpfile.js below
'use strict';
var gulp = require('gulp');
var less = require('gulp-less');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
var csscomb = require('gulp-csscomb');
var autoprefixer = require('gulp-autoprefixer');
function swallowError (error) {
// If you want details of the error in the console
console.log(error.toString());
this.emit('end');
}
/* Task to compile less */
gulp.task('compile-less', function() {
gulp.src('./src/less/style.less')
.pipe(less())
.on('error', swallowError)
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(csscomb())
.pipe(gulp.dest('./prod/css/'));
});
/* Task to watch less changes */
gulp.task('watch-less', function() {
gulp.watch('./src/**/*.less' , ['compile-less']);
});
gulp.task('serve', function () {
// Serve files from the root of this project
browserSync.init({
server: {
baseDir: "./prod/"
}
});
gulp.watch("./src/less/*.less").on("change", reload);
gulp.watch("./prod/*.html").on("change", reload);
});
/* Task when running `gulp` from terminal */
gulp.task('default', ['watch-less', 'serve']);
(I used this code as example).
So gulp works great with style.less
file and compiles it correctly and fast, but when I'm trying to change colors.less
file, for example, or other imported file, gulp doesn't work. I need to stop gulp and restart it again manually to compile changes in imported files.
What's wrong?