Open Noveller opened 4 months ago
I am not sure to understand the problem you have. This plugin is made to work with ViteJS like this:
// vite.config.js / vite.config.ts
import VitePluginSvgSpritemap from '@spiriit/vite-plugin-svg-spritemap'
export default {
plugins: [
VitePluginSvgSpritemap('./src/icons/*.svg', {
styles: 'src/scss/spritemap.scss'
})
]
}
And use like this in your app. ViteJS will transform /__spritemap to your vite assets directory.
<svg>
<use xlink:href="/__spritemap#sprite-spiriit"></use>
</svg>
You will need aditional setup if you have a backend like wordpress/drupal/laravel...
What is your environment?
Thx for replying.
I am using this package to generate the svg sprite. I dev mode everything works fine because dev environment provides the correct path to the svg sprite. But I don’t understand how to provide path to the svg sprite in production mode.
<svg><use xlink:href="/__spritemap#sprite-spiriit"></use> </svg>
__spritemap string will replace with correct path to the svg by dev env. But how to use it in production mode?
On production, the plugin replace /__spritemap
with the vitejs assets directory.
Can you provide a small reproduction to understand what is not working for you? Do you have a particular vitejs configuration?
I think I might be facing the same issue. I'm building a library component in vue, to be used in another app.
When building, the spritemap does get put out to the dist/assets
folder, but when importing my component (which uses vite-plugin-svg-spritemap for icons), the url in the build points to nothing (/assets/spritemap.4bdde031.svg
).
When I manually copy the spritemap.4bdde031.svg
to the apps public/assets
folder, it works.
How to use as npm package. I have a problem with not being able to set the path to the sprite file in production mode