To use an SVG spritemap with Laravel Vite, you can follow these steps:
- Install the
vite-plugin-svg-spritemappackage by running the following command in your project directory:
npm install vite-plugin-svg-spritemap --save-dev
- Configure the plugin in your
vite.config.jsfile:
import svgSpritemap from 'vite-plugin-svg-spritemap';
export default {
// other Vite config options
plugins: [
svgSpritemap({
// specify the path to your SVG files
glob: 'resources/svg/*.svg',
output: 'public/svg/spritemap.svg', // specify the output path for the spritemap
}),
],
};
- In your HTML file, include the spritemap using the
useelement:
<svg class="icon">
<use xlink:href="/svg/spritemap.svg#uptime"></use>
</svg>
Make sure to adjust the paths and filenames according to your project structure.
Note: The vite-plugin-svg-spritemap plugin will generate a spritemap SVG file based on the SVG files in the specified directory. The xlink:href attribute in the use element references the spritemap file and specifies the ID of the specific SVG icon you want to use.
Let me know if you have any further questions!