D
D
Dimox2017-04-04 10:08:30
gulp.js
Dimox, 2017-04-04 10:08:30

Gulp-watch - how to run browser-sync when changing / adding a folder / file?

Greetings.
The task is to launch browserSync if I add or remove the specified folder (/js/) to the project, or add/remove/change js files in it (all this is done manually).
gulpfile.js looks like this:

var gulp = require('gulp'),
    browserSync = require('browser-sync').create(),
    watch = require('gulp-watch');

gulp.task('default', ['webserver', 'watch']);

var path = {
    watch: {
        js: '../js/**/*.js',
    },
};

gulp.task('webserver', function() {
    browserSync.init({
        proxy: 'localhost'
    });
});

gulp.task('watch', function() {
    gulp.watch(path.watch.js).on('change', browserSync.reload);
});

Here, browserSync only works if I changed the js file, and if the / js / folder with the file existed before gulp was launched.
Suggest a solution, please.
The project structure is as follows:
/project/
-- /dev/
---- gulpfile.js
-- /js/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Zharov, 2019-06-06
@Roman52

Better late than never :) - googled this question too, stumbled upon this thread with no answer.
As a result, I found a solution - a plugin for sublime https://github.com/NicoSantangelo/sublime-gulp
It allows you to run gulp directly in syblime and set hotkeys to start / restart gulp - a.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question