#HMR (Hot Module replace) for Fronted dev mode

1 messages · Page 1 of 1 (latest)

wind ember
wind ember
agile river
#

Couldn’t you don this with the —hot arg

smoky oxide
#

I tried doing that but I can’t get the browser to reflect my changes without refreshing.

wind ember
#

@agile river, --hot watch and restarts the server, but does not notify the browser about the need to update a certain part of the content. Now --hot works like nodemon.

As front-end developers, we need to update the content of the browser, but without reloading the page.

Please, watch example HMR by Vite above.

#

@smoky oxide, because you need Websockets to notify the browser about updates.

Here is an example https://github.com/mi4uu/bun-react-template, a working version of Websockets + window.reload.

But it seems to me that without improvements to `Bun.serve', it will not be possible to implement the real HMR.

agile river
#

woops lemme make that an mp4

#

@wind ember

#

wait

#

this might have just been the webpack dev server

#

for cra

wind ember
#

Try doing this on a native Bun)

agile river
#

ah yea i see what your getting at

wind ember
#

Here's how HMR is implemented in Vite:

There is a createHotContext function in clients.ts which provides the methods needed by HMR.

In importAnalysis.ts, the result of the createHotContext call is inserted into import.meta.hot for each of the modules.

https://github.com/vitejs/vite/blob/main/packages/vite/src/client/client.ts
https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/importAnalysis.ts

GitHub

Next generation frontend tooling. It's fast! Contribute to vitejs/vite development by creating an account on GitHub.

GitHub

Next generation frontend tooling. It's fast! Contribute to vitejs/vite development by creating an account on GitHub.

#

@night anvil, can we expect HMR in Bun out of the box?

I think it will be much faster than Vite.

wide girder
#

Framework API ( Bun.App ) should be able to do that

wind ember
#

@wide girder, what do you mean?

wide girder
#

that it should have HMR