Hey!
Vite exposes the base path as import.meta.env.BASE_URL
, so you can use that variable to build the URLs if you need to, e.g.:
const getImg = () => {
const base = import.meta.env.BASE_URL;
return type === "r"
? `${base}images/icon-rock.svg`
: type === "s"
? `${base}images/icon-scissors.svg`
: `${base}images/icon-paper.svg`;
};
You can also import the assets and let Vite optimize them:
import p from "./icon-paper.svg";
import r from "./icon-rock.svg";
import s from "./icon-scissors.svg";
const getImg = () => {
return type === "r" ? r : type === "s" ? s : p;
};
The CSS paths should work with the --base
flag:
<motion.div className="bg-[url('/images/bg-triangle.svg')]" />