karolis-sh / electron-snowpack

Use Snowpack and esbuild for Electron app development
MIT License
50 stars 8 forks source link

src/renderer/* -> HMR/Refresh #40

Closed qwertasyx closed 3 years ago

qwertasyx commented 3 years ago

I was expecting that as soon as i change something the view should update. in the Iogs can see that snowpack is doing its thing as expected, but i have to manually reload (Ctrl+r) to see the changes.

Am i missing something essential or misinterpreted how it should behave?

karolis-sh commented 3 years ago

@qwertasyx you're probably missing something. Snowpacks HMR in electron should work just like in the browser. You can open the localhost URL and debug it in the browser. The basic examples this project provides seem to be working.

qwertasyx commented 3 years ago

Thanks for your quick response :). I tried with the svelte and the hello world example.

Somehow import.meta.hot is undefined. As far as i understand snowpack (just getting started) this gets ommited when bundling for production. The NODE_ENV is set to 'development' so that should be ok.

Maybe you have an idea where i can look into a bit more to figure that out.

qwertasyx commented 3 years ago

after setting devOptions: { hmr: true } it works like expected.

In snowpack dev() its set implicit so i´m not sure where it gets lost along the way :D

karolis-sh commented 3 years ago

Thanks for the clarification, it seems that the Snowpack's CLI and JavaScript API works a bit differently. Seems like an easy fix.

karolis-sh commented 3 years ago

@qwertasyx could you provide an example of how the hmr becomes undefined? I checked the example and the hrm is present, unless I explicitly define hmr to false. I though there might be an issue with deep merging of the snowpack config if you'd change any other devOptions field, but it doesn't seem to be the case.

qwertasyx commented 3 years ago

@karolis-sh I just put a console.log before the import.meta.hot in the index.js. But i didn´t really figure out why it was undefined. I will take another look in the coming days, maybe i will find smt that helps.

I assume since no one else brought this up its probably related to my setup specifically somehow, so i tried the plane examples on a W10 machine and an ubuntu system, with the same result. I just cloned the repo and did 'npm i' in the according example. Did i forget something obvious? (node14.15.0)

karolis-sh commented 3 years ago

Ah, I can reproduce with your described steps on a mac also. By installing from the root of the project with yarn, or in another separate project the import.meta.hot seems defined. Yeah, this is a weird one.