parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.4k stars 2.26k forks source link

Automatically close the browser tab opened by Parcel when HMR enabled #3027

Open Kogia-sima opened 5 years ago

Kogia-sima commented 5 years ago

🙋 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.

Taym95 commented 5 years ago

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

mischnic commented 5 years ago

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

Taym95 commented 5 years ago

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

gregid commented 5 years ago

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