crxjs / chrome-extension-tools

Bundling Chrome Extensions can be pretty complex. It doesn't have to be.
https://crxjs.dev/vite-plugin
2.71k stars 181 forks source link

HMR not working #892

Open mp3por opened 2 months ago

mp3por commented 2 months ago

Build tool

Rollup

Where do you see the problem?

Describe the bug

When I open the PopUp and then make a change in the code base, the pop-up does not reflect that change until I manually refresh the popup by closing and opening it again.

Reproduction

https://github.com/JohnBra/vite-web-extension

Logs

No response

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 102.91 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
    pnpm: 9.1.2 - /opt/homebrew/bin/pnpm
    Watchman: 2024.05.06.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 125.1.66.118
    Chrome: 125.0.6422.142
    Safari: 17.5
  npmPackages:
    @crxjs/vite-plugin: ^2.0.0-beta.23 => 2.0.0-beta.23
    vite: ^5.2.13 => 5.2.13

Severity

annoyance

Toumash commented 2 months ago

Im not sure why i cannot run your extension on windows, but you're clearly not using vite for HMR. Nodemon works by watching files changing and rebuilding the whole thing without hmr.

image

To use any vite dev feature (including hmr) use vite dev mode. image

Toumash commented 2 months ago

I have no idea why it doesnt work with existing config in your project but i've managed it to work with some changes. Adjust the vite.config to your needs - i've removed some things just to not debug it faster. Manifest defined by defineManifest is better as it (probably) allows the crx to adjust it automatically (at least web_accessible_resources are autogenerated with crxjs)

If that works for you then lets close this issue @mp3por

https://github.com/JohnBra/vite-web-extension/pull/34

demo.gif ![demo](https://github.com/crxjs/chrome-extension-tools/assets/9840635/9c6ff069-dd8b-4a3e-ab7f-cb1926fb33bd)
mp3por commented 2 months ago

I have no idea what does nowork with fs-extra in your project but i've managed it to work no problem. Adjust the vite.config to your needs - i've removed some things just to not debug it faster

If that works for you then lets close this issue @mp3por

JohnBra/vite-web-extension#34

demo.gif

I will check during the weekend and come back to you.

Toumash commented 1 month ago

@mp3por and?

mp3por commented 1 month ago

@Toumash

I was not able to get the HMR working. When I change my code to look like yours however I get the following issue. This screen keeps flickering. I don't understand enough to debug further.

image
Toumash commented 1 month ago

@Toumash

I was not able to get the HMR working. When I change my code to look like yours however I get the following issue. This screen keeps flickering. I don't understand enough to debug further.

image

try it one more time. This is an issue i also have sometimes when swiching branches - restarting the dev server several times helps (and if not remove .vite or node_modules, npm install and run again). It is independent from HMR but something with a server startup.