1.0.5 • Published 8 years ago

browser-sync-close-hook v1.0.5

Weekly downloads
113
License
MIT
Repository
-
Last release
8 years ago

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: