SpiriitLabs / vite-plugin-svg-spritemap

Vite plugin to generate svg spritemap
MIT License
56 stars 4 forks source link

How to work with monorepo? #59

Open numfin opened 3 weeks ago

numfin commented 3 weeks ago

Vite

I have 2 projects:

  1. Component library with svg-spritemap plugin. Everything works, storybook works, etc.
  2. Main app - no icons showing.

After investigating - I found that app inserting /assets/spritemap... which is correct path inside component library dist folder, but my main app doesn't know anything about /assets/spritemap....

So I'm wondering what kind of magic I have to do to tell vite to dynamically insert spritemap path into xlink-href.

Shortly

Now: localhost:5173/assets/spritemap.svg I want: localhost:5173/@fs/path_to_uikit/dist/assets/spritemap.svg

numfin commented 3 weeks ago

After beating my head for a while i found "solution" which was working for me: vite.config.ts

export default defineConfig(({command}) => ({
  base: command === "build" ? join("/@fs", __dirname, "dist") : "/",
numfin commented 2 weeks ago

Ok this "solution" worked only in devserver so manual file copying with vite-plugin-static-copy fixed it for me:

    viteStaticCopy({
      targets: [{ src: 'relative_path_to_package/dist/assets/*.svg', dest: './assets/' }],
    })