Parcel: Automatically close the browser tab opened by Parcel when HMR enabled

Created on 14 May 2019  路  4Comments  路  Source: parcel-bundler/parcel

馃檵 feature request


Parcel CLI has an option '--open' which enables to opens bundled file with a browser automatically. However, if you stopped the HMR server with Ctrl + C, that tab does not close automatically, and then you have to close the tab manually.

馃 Expected Behavior


When the websocket to the HMR server has disconnected, current browser tab closes automatically.

馃槸 Current Behavior


Browser tab remains and you have to close it manually.

馃拋 Possible Solution


See the implementation of suan/instant-markdown-d

馃敠 Context

馃捇 Examples

$ cd /your/project/root/
$ ./node_modules/.bin/parcel --open firefox --target browser index.html

And press Ctrl + C. You can see the browser tab opened by parcel command does not close automatically.

Feature

Most helpful comment

This could only be a helpful feature if provided as an option and not a default, e.g. --autoclose

All 4 comments

I would like to work on this but, how it is possible to execute window.close(); from the server side?

I'm not really convinced this is a helpful feature (would be rather unexpected).

Regarding implementation: The HMR server would need to emit a new event type ("close?") and the hmr runtime would then execute window.close: https://github.com/parcel-bundler/parcel/blob/ee0acf2a384c39ff8d04bcb66c8acd60a79edf22/packages/core/parcel-bundler/src/builtins/hmr-runtime.js#L67

AH, I got it Thanks! I will try to submit PR :)

This could only be a helpful feature if provided as an option and not a default, e.g. --autoclose

Was this page helpful?
0 / 5 - 0 ratings