Inject SVG content into components
.
npm i vite-plugin-svg-inject -D
import { defineConfig } from "vite";
import SVGInjectPlugin from "vite-plugin-svg-inject";
export default defineConfig({
plugins: [
// Target:
// - "react" - If JSX library is React
// - "other" (default) - For others libraries
SVGInjectPlugin(target)
],
})
import MyIcon from './images/icon.svg';
function MyComponent() {
return (
<div>
<MyIcon width="32" fill="red" />
</div>
);
}