grunt-open
grunt-open copied to clipboard
openOn should only open once when the event first occurs
I have a grunt serve
task that does a build, starts a web server, then uses grunt-open to launch the web page once the server has fully started. I use the openOn
option because it is the most reliable way to ensure that the asynchronous server startup is complete and thereby avoid launching the page before the server is ready.
Unfortunately, the open task continues to run every time the event is fired (in my case, on every server restart). This results in every change to a server-dependent file not just restarting the server but also popping up a new tab in the browser despite the open task running only once at initial startup.
The simplest fix is to replace grunt.event.on(
with grunt.event.once(
. The implementation is a matter of opinion, it might be preferable for backwards compatibility to introduce an openOnceOn
option to explicitly open only once. Either way it would be good to update the documentation for openOn
to specify whether it opens just once or every time the event is triggered.
This would certainly be useful. I am experiencing the same situation
Oh sorry, I never submitted my pull request for this!
#29 is the simplest solution but we'll see what folks think about backwards compatibility issues.
Didn't work for me unfortunately