BrowserSync / browser-sync

Keep multiple browsers & devices in sync when building websites. https://browsersync.io
https://discord.gg/2d2xUThp
Apache License 2.0
12.17k stars 754 forks source link

BrowserSync file watcher can't ignore files #1096

Open igidas opened 8 years ago

igidas commented 8 years ago

Issue details

I'm having trouble with BrowserSync file watcher. I can't ignore some files. What I'm trying to do is to reload browser only after my Twig template files are compiled mannualy by watching Gulp 'task_stop' option, but also I'm watching for other assets compile with BrowserSync file watcher.

Steps to reproduce/test case

I'm watching all assets folder, like:

files: [dir.assets + '/**/*'],

then I try to exclude twig files like:

files: [dir.assets + '/**/*', '!' + dir.assets + '/**/*.twig'],

it still refreshes browsers after twig file edit. I try to pass ignore option to Chokidar, but it works only then fn callback is defined, like:

files: [
                    {
                        match: [dir.assets + '/**/*'],
                        fn: function (event, file) {},
                        options: {
                            ignored: dir.assets + '/**/*.twig'
                        }
                    }
                ],

After looking into BrowserSync code in file-watcher.js, I think it could be a bug because of Default CB when not given.

Please specify which version of Browsersync, node and npm you're running

/// Config
browserSync: {
    port: 3002,
    server: {
        baseDir: '../../../../../',
        index: 'index.html'
    },
    startPath: 'src/Frontend/Themes/artimart/_development/build',
    proxy: false,
    files: [
    {
        match: [dir.assets + '/**/*'],
                        fn: function (event, file) {}, // Empty fucntion required because of BrowserSync always filechange emmiting bug
                        options: {
                            ignored: dir.assets + '/**/*.twig'
                        }
                    }
                    ],
                reloadDelay: 200, // Prevents this bug: https://github.com/BrowserSync/browser-sync/issues/277
                ui: {
                    port: 9999
                },
                logConnections: true,
            },
            // Then these tasks are completed, BrowserSync reloads page
            reloadAfter: ['twig']
        }

// Gulp task
Gulp.task($taskId, function (callback) {
    BrowserSync.init($taskOptions.browserSync);
    callback();
});

Gulp.addListener('task_stop', function (data) {
    if ($taskOptions.reloadAfter.indexOf(data.task) > -1) {
        BrowserSync.reload();
    }
});
eduarddotgg commented 8 years ago

I have similar issue. i have this configuration:

files: [
    src + '/**/*.pug',
    '!' + src + '/**/*.jspm.js',
    src + '/**/*.js',
    src + '/**/*.css'
],

And browser sync still watches *.jspm.js files.

Very sad that this issue is opened from May 13.(

dennisreimann commented 6 years ago

Same here, negated paths seem to be ignored (triggering reloaded as well) in the files option.

lunelson commented 6 years ago

there is also an ignore top-level option, it's not in the documentation but it is in the release notes here https://github.com/BrowserSync/browser-sync/releases/tag/v2.23.0; otherwise, the way to ignore seems to be in watchOptions.ignored option.

lunelson commented 4 years ago

(please close)

vadimcoder commented 2 years ago

This worked for me:

ignore: ["**/node_modules/**", "**/.idea/**"],