When using Vite, static asset handling is a bit different from Laravel Mix. Vite treats /public as the root for serving static assets, so you should be able to reference images relative to the public directory without needing to import them.
Here's how you can reference your static images in your Vue templates with Vite:
- Move your images to the
publicdirectory if they are not already there. For example, you might have a structure like this:
project-root/
|-- public/
| |-- storage/
| |-- images/
| |-- vendor/
| |-- leaflet/
| |-- dist/
| |-- marker-icon-2x.png
- Reference the image in your Vue component using the absolute path from the root of the
publicdirectory:
<img src="/storage/images/vendor/leaflet/dist/marker-icon-2x.png">
This should work because Vite will serve files from the public directory as static assets. You don't need to import them as you would with JavaScript modules or other assets that require processing.
If you find that the images are not loading, make sure that the path is correct and that the public directory is configured correctly in your Vite configuration.
Remember that this approach is for static assets that do not need to be processed by Vite. If you need to apply transformations or optimizations to your images, you might still need to import them to leverage Vite's asset handling capabilities.