Created
June 26, 2015 20:03
-
-
Save timthez/d1b29ea02cce7a2a59ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Closer plugin example | |
*/ | |
(function ($window, $document, bs) { | |
var socket = bs.socket; | |
socket.on("disconnect", function (client) { | |
window.close(); | |
}); | |
})(window, document, ___browserSync___); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var browserSync = require('browser-sync'); | |
.task('webserver', function() { | |
browserSync.use({ | |
plugin: function () { /* noop */}, | |
hooks: { | |
'client:js': require("fs").readFileSync("./closer.js", "utf-8") | |
} | |
}); | |
browserSync(['public/**/*.*'],{ | |
port: 9001, | |
open: true, | |
server: { | |
baseDir: './public' | |
}, | |
ui: { | |
port: 9002 | |
} | |
}); | |
}) |
@electricjesus I don't think so. I've rewritten the closer to:
/* jshint -W117 */
(function(window, bs) {
bs.socket.on('disconnect', function() {
window.close();
});
})(window, ___browserSync___);
closer.js
___browserSync___.socket.on('disconnect', window.close.bind(window));
thank you for your work on that, it was really annoying, productivity +1
inspired me to do a little module: https://www.npmjs.com/package/browser-sync-close-hook
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IIFE uses global
window
instead of$window
arg: https://gist.github.com/timthez/d1b29ea02cce7a2a59ff#file-closer-js-L8is this intentional?