B
B
Beaver Nubyar2017-02-16 15:18:40
Automation
Beaver Nubyar, 2017-02-16 15:18:40

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

3 answer(s)
I
iBird Rose, 2017-02-16
@iiiBird

gulp-watch https://www.npmjs.com/package/gulp-watch can do that. if you set the right path. not specific files.

A
Anton, 2017-02-16
@Ooos

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');
    });
});

Z
zooks, 2017-02-16
@zooks

gulp-changed or gulp-watch to help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question