Closed aklinker1 closed 1 year ago
Fixed. In summary, the plugin stored information about the current build process in memory. Before, since only a single vue plugin was used, some internal variables are set when spinning up the dev server and all subsequent transformations (HTML files and script files) believe they have a dev server. This lead to the plugin trying to configure HMR for non dev server build steps, like content scripts.
I've setup a hardcoded list of plugin names that can be updated if more plugins use this same approach.
To use Vue in content scripts, you'll need to add the Vue plugin to your scriptViteConfig
as well as your regular plugin list.
I have a similar problem.
My project only has background script, no content script, and it include pinia.
@ListenV No HTML pages either? Could you share a minimal reproduction?
@aklinker1 demo-vue
is just that.
demo-vue
still has this problem
Hmm, I'll have to double check, but demo-vue
was the project I used to fix this bug. I'm quite confident it's working.
Still has problem in popup for me
Sorry for the late replies, been busy these last few weeks. @ListenV, I've verified that the demo-vue extension works from my active development clone and a brand new clone:
No error messages in the console from the extension. Make sure you're up to date with main
.
@yujinlin0224 You're having a problem with an HTML page? That's not related to this issue with Vue in content scripts. Could you open a new issue and share a minimal reproduction?
@aklinker1 I opened https://github.com/aklinker1/vite-plugin-web-extension/issues/102, please check
Hey all, I have reverted the fix for this issue because it was causing a different bug, #102. Instead, I applied a different fix...
For v3.0.7
and onward, just add the Vue plugin in the regular plugins field, not the scriptViteConfig
defineViteConfig({
plugins: [
vue(),
webExtnesion({
- scriptViteConfig: {
- plugins: [vue()],
- },
}),
],
});
Documenation is up to date: https://vite-plugin-web-extension.aklinker1.io/guide/frontend-frameworks.html#vue
Summary
Works fine in production. When including a vue app in a content script, the content script errors out.
It looks like the vue plugin thinks it's running in dev mode, so tries it to include
import.meta.hot
references to enable HMR, but the content scripts are never built in dev mode, and thusimport.meta.hot
is replaceed with(void 0)
.Reproduction
The
packages/demo-vue
extension has this problem. Runpnpm dev
then go togoogle.com
and open the console. This is where the screenshots from above come from.Environment