aklinker1 / vite-plugin-web-extension

Vite plugin for developing Chrome/Web Extensions
https://vite-plugin-web-extension.aklinker1.io/
MIT License
553 stars 48 forks source link

V2 HMR #55

Closed aklinker1 closed 1 year ago

aklinker1 commented 1 year ago

Couple of comments:

  1. There can only be 1 dev server running at a time
  2. We can't start Vite in dev mode because the manifest-loader plugin needs to effectively build everything so it can output a manifest with all the outputs listed in it
  3. HMR only works for HTML pages, like V1
  4. From the client pages, we can't load the scripts from http://localhost:3000 because of Chrome's rules against loading external code. It just blocks the file from being downloaded

So instead of serving a file over localhost when there's a change, we write that file to the output director and send a message to the client telling it to HMR, but based off a file path instead of a URL (http://localhost:3000/popup/index.js/popup/index.js). These files can be loaded correctly!

Todo

aklinker1 commented 1 year ago

This is working, but the code is a mess. I'll redo this PR