#Importing static assets as url
1 messages · Page 1 of 1 (latest)
you can just import the asset for most times, but if its a common extension like html then you may need to do the manual approach:
import icon from "./icon.png" with { type: "file" };
in normal runtime, it will print a path to the file, and in bun file.html thing (the fullstack & static html builder) it'll copy it as an asset and add hash (so like vite)
ok, I've tried it, but it doesn't seem to follow my path re-mapping
@/assets/img/switch-on.svg
in my tsconfig
"rootDir": ".",
"paths": {
"@/*": [
"./src/*"
]
the source:
import imgSwitchOnUrl from '@/assets/img/switch-on.svg' with { type: 'file' };
...
<img
className="ToggleIcon"
alt=""
src={value ? imgSwitchOnUrl : imgSwitchOffUrl}
onClick={onToggle}
/>
the result:
<img class="ToggleIcon" alt="" src="@/assets/img/switch-on.svg">