In my project, during dev everything works great but my target app seems to not parse imports that start with "/" properly ( I am developing for a local app, not for a website / webapp).
How can I get Vite to ommit the / at the beginning of import statements only when building?
For example, if I have a file in my public folder that I import like so:
import something from '/file.svg
I need it to bundle as:
import something from 'assets/file.svg
But instead I am getting:
import something from '/assets/file.svg
I have tried modifying vite.config.js to include any of the following:
base: '',base: '/',base: './',
Check Vite version in your project. It seems there was an issue with
baseoption in old versions.I don't know the exact issue. But this one is related to
baseoption. And it was fixed in 2022.Update Vite and its plugins in your project and try again with empty string. (value
./also works according to the Vite documentation).Pay attention that you must specify the
baseoption on top-level config object (NOT insidebuildoption).For example, this part of
vite.config.jsfile demonstrates it:For Vite version
5.1.5installed on my machine I get this result HTML file in the output (dist) folder: