browser-sync-close-hook
v1.0.5
Published
Closes Browser Tabs which are connected to browserSync once browserSync disconnects (when stopping gulp for example)
Downloads
64
Readme
browser-sync-close-hook
Closes Browser Tabs which are connected to browserSync once browserSync disconnects (when stopping gulp for example).
Install
> npm install browser-sync-close-hook --save-dev
Usage in gulpfile.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.
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