T
T
tuxx2018-08-14 12:29:20
JavaScript
tuxx, 2018-08-14 12:29:20

Gulp watch only runs 1 time per file?

For gulp 4 there is a watch task:

let paths = {
    scss:    'frontend/scss',
    js:      'frontend/js',
    site_js: 'web/js/site.js',
    fonts:   'frontend/fonts',
    images:  'frontend/images',
    dest:    'web/assets',
};

gulp.task('watch-scripts', () => {
    gulp.watch([
        paths.site_js,
        paths.js + '/**/*.js',
    ], gulp.series('scripts'));
});

For paths.site_js watch only works 1 time after the task is started\restarted. For paths.js + '/**/*.js' is run whenever the matching files change. At the same time, for the 'web/js/*.js' rule , watch starts as it should every time the site.js file changes, but I need only it to be tracked, and not everything in the web/js folder

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2018-11-23
@andreybold

I stumbled upon this question when I was solving the same problem myself. Through trial and error, I found that it does not work if you specify a specific file (i.e. without a wildcard, etc.)
My crutch solution:

// Было
watch('./resources/js/admin.js', series(admin));
// Стало
watch('./resources/**/admin.js', series(admin));

Might be useful to someone.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question