es-module-shims icon indicating copy to clipboard operation
es-module-shims copied to clipboard

Replace resolved imports in esModuleShims (for hot reload)

Open jogibear9988 opened this issue 1 year ago • 5 comments

Hello,

I implemented my own WebComponent Library (https://github.com/node-projects/base-custom-webcomponent) wich also has it's own hot reload mechanism. But at the moment you could only reload the components (cause I replace the constructor in the customElemnt registration), but not referenced javascript code (cause the browser only loads once). Would it be possible that I replace the stored javascript wich was resolved by your library when loaded via importShim? Is there any access to it?

jogibear9988 avatar Jul 15 '23 06:07 jogibear9988

Here is how I reload atm: https://github.com/node-projects/base-custom-webcomponent/blob/master/src/HotModuleReplacement.ts

jogibear9988 avatar Jul 15 '23 06:07 jogibear9988

Thanks for sharing. There is actually a hot reload implementation for this project in https://github.com/guybedford/es-module-shims/pull/269, I just never landed it (not sure why... it works fine!). The main issue is just that it needs integration with a server that can send the reload events, but Chomp does support it as well.

If you try it out do share if it works for you.

guybedford avatar Jul 31 '23 03:07 guybedford

Will try. At the moment I‘ll switch our complete project to use native import maps. When this is done I‘ll can try

jogibear9988 avatar Jul 31 '23 06:07 jogibear9988

The switch to importmaps takes longer as expected, but i will work on this

jogibear9988 avatar Aug 12 '23 17:08 jogibear9988

I tried it with a good ol browser-sync server a few months back, it was working fine. If I remember correctly, I had a couple issues with the query parameter replacement not checking existing query params: https://github.com/guybedford/es-module-shims/blob/087eae381eaedcb5a22627d7afbde2d14ce4755e/src/hot-reload.js#L32-L35

dmnsgn avatar Dec 02 '23 11:12 dmnsgn