antfu-collective / vitesse-webext

⚡️ WebExtension Vite Starter Template
MIT License
2.93k stars 225 forks source link

Invalid assets URL in dev mode #156

Closed Elliot67 closed 8 months ago

Elliot67 commented 1 year ago

Describe the bug

In development mode, assets inside the src/assets folder cannot be imported from components.

Explanation

Importing an image with <img src="/assets/icon.svg" /> will resolve to <img src="/assets/icon.svg" /> instead of <img src="http://localhost:3303/assets/icon.svg" />. When the app is builded, the image will resolve to /dist/assets/icon-03081ed2.svg which works.

The provided example inside src/options/Options.vue currently only works because the same file exists in the extension/assets folder.

Note :

Possible solutions

Reproduction

Rename src/assets/icon.svg to something else and fix the import inside src/options/Options.vue

System Info

Windows & Chrome

Used Package Manager

yarn

Validations

chen99-long commented 10 months ago

I have also encountered this problem, how to solve it?

Elliot67 commented 10 months ago

@chen99-long , I worked around the issue by adding the <base href="http://localhost:3303/" /> tag in the <head> of my options & popup html pages. Vite seems to remove the tag at build time but it can create other issues depending on your extension.

I think the proper fix should be done inside the Vite configuration directly.

chen99-long commented 10 months ago

Thank you very much

sgarcia-dev commented 9 months ago

Facing the same issue at the moment even on a completely new project. @antfu is this a known issue?

QC2168 commented 9 months ago

same issues