Answer the question
In order to leave comments, you need to log in
How to track new files in Gulp?
Can you please tell me how to make Gulp watch for new files and perform some task?
For example, when adding new icons, regenerate the sprite or merge new CSS files as well. Now I have to restart Gulp so that it sees the new files and includes them in the task.
Answer the question
In order to leave comments, you need to log in
gulp-watch https://www.npmjs.com/package/gulp-watch can do that. if you set the right path. not specific files.
var gulp = require('gulp'),
browserSync = require('browser-sync'),
less = require('gulp-less'),
concat = require('gulp-concat-css'),
autoprefixer = require('gulp-autoprefixer')
//Запускает локальный сервер в реальном времени
gulp.task('browser-sync', function () {
browserSync({
server: {
baseDir: 'app'
}
});
});
gulp.task('style', function () {
gulp.src('app/dist/less/**/*.less')
.pipe(less())
.pipe(concat('style.css'))
.pipe(autoprefixer({
browsers: ['last 12 versions'],
cascade: false
}))
.pipe(gulp.dest('app/dist/css/'))
.pipe(browserSync.reload({
stream: true
}))
});
gulp.task('html', function () {
gulp.src('app/**/*.html')
.pipe(browserSync.reload({
stream: true
}));
});
//Отслеживает изменение в файлах и запускает необходимое функцию
gulp.task('watch', function () {
gulp.run('style', 'html'); //запуск
gulp.watch('app/dist/less/**/*.less', function (event) {
gulp.run('style');
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question