Closes Browser Tabs which are connected to browserSync once browserSync disconnects (when stopping gulp for example)
npm install browser-sync-close-hookbrowser-sync-close-hook
---
Closes Browser Tabs which are connected to browserSync once browserSync disconnects (when stopping gulp for example).
Install
---
``sh`
> npm install browser-sync-close-hook --save-dev
Usage in gulpfile.js
---
`js
const autoClose = require('browser-sync-close-hook');
gulp.task('serve', ['watch'], () => {
browserSync.use({
plugin() {},
hooks: {
'client:js': autoClose, // <-- important part
},
});
browserSync({
ui: false,
notify: false,
server: {
baseDir: './public',
middleware: [historyApiFallback()],
},
});
});
`
Source
---
The only thing this module does is exporting a function string which useses the clients browsers window.close function to close the tab.
`js``
module.exports = "___browserSync___.socket.on('disconnect', window.close.bind(window));";
Credits
---
for providing the original solutions:
- https://gist.github.com/timthez
- https://gist.github.com/shakyShane/3d5ec6685e07fd3227ba
for the discussion which let to solving the issue of too many open tabs:
- https://github.com/BrowserSync/browser-sync/issues/84