aklinker1 / vite-plugin-web-extension

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

Failed to resolve module from public directory #77

Closed aklinker1 closed 1 year ago

aklinker1 commented 1 year ago

Overview

V2+ only. For the vue templates, when I tried to reference an image like so, the build failed:

<img src="/icon-with-shadow.svg">
Screen Shot 2023-03-03 at 5 11 24 PM

Since internally, the public directory is disabled for the HTML and script builds, if a plugin relies on it to resolve root level modules, like the vue plugin does for loading modules at a given src, the build can fail.

The solution in this case is easy, use a string literally instead, and it won't be treated as a module:

<img :src="'/icon-with-shadow.svg'">

But you shouldn't have to do that. Child builds should be able to resolve modules in the public directory.

Potentially, we could enable the public directory for child builds. It would result in the files being copied multiple times, but would be a simple solution.

Steps to Reproduce

pnpm create test -t vue-ts
cd test
# Update pages/Popup.vue with <img src="/icon-with-shadow.svg">
pnpm dev

Changes