browser-sync-close-hook

1.0.5 • Public • Published

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:

for the discussion which let to solving the issue of too many open tabs:

Readme

Keywords

none

Package Sidebar

Install

npm i browser-sync-close-hook

Weekly Downloads

16

Version

1.0.5

License

MIT

Last publish

Collaborators

  • elgubenis