nuxt-modules / svg-sprite

Optimize SVG files and combine them into sprite
https://codesandbox.io/s/github/nuxt-community/svg-sprite-module/
MIT License
295 stars 41 forks source link

Custom input path outside the nuxt 3 app doesn't work #281

Open jfernandezpe opened 1 year ago

jfernandezpe commented 1 year ago

Hi,

I use svg-sprite-module in a couple of Nuxt 2 apps in a monorepo andboth apps share the same svgs so with svgSprite.input option I point to the asset package and it works.

Now I'm creating a new Nuxt 3 app in the monorepo and it seems that the same strategy doesn't work, the icons do not load in the nuxt 3 app. After some debugging, I found that svg-sprite-module uses nitro's storage layer to deal with the filesystem. And because I'm pointing to a folder outside nitro's scope, svgSprite cannot the shared SVGs.

Am I doing something wrong? May you suggest any workaround? I would be happy to write a fix to this issue and send you a pull request but I'm not sure where to start.

I create a basic reproduction scenario, without configuring lerna or yarn workspaces: https://github.com/jfernandezpe/svg-sprite-module-error-reproduction

Thank you for your time!

farnabaz commented 1 year ago

Hey @jfernandezpe Feel free to open a PR to resolve this 👍 Looking forward to seeing your improvements 🙂

smoglica commented 1 year ago

A possible workaround could be by playing with alias. Config example:

import { join } from 'path';
import { defineNuxtConfig } from 'nuxt/config';

export default defineNuxtConfig({
    srcDir: 'src/',
    modules: ['@nuxtjs/svg-sprite'],
    svgSprite: {
        input: '~/src/assets/sprite/svg',
        output: '~/src/assets/sprite/gen'
    },
    alias: {
        '~/src/assets/sprite/gen': join(__dirname, 'src/assets/sprite/gen'),
    }
});

up for the fix!