Jevon617 / unplugin-svg-component

generate a vue/react component through svg files, supporting svg file HMR, Tree-shaking, SSR and TS hint.
MIT License
58 stars 5 forks source link

[Feature Request] Support multiple icon directories #10

Closed voknelis closed 1 year ago

voknelis commented 1 year ago

Problem to solve

This feature would allow the usage of SVG's from various directories.

Currently, the envisioned use-case involves storing all the SVG files within a singular folder. However, it's no longer align with my usage.

For instance, consider a scenario where we have 2 completely separated icon sources: an npm package called "my-icons" and some project folder titled "local-icons". Now, I have to either choose a singular icon source or set iconDir: "." plugin parameter to the project's root, which is rather an inconvenient choice.

Proposed solution

1. Modify iconDir parameter type

The possible solution might be changing iconDir parameter type to string | string[], so that we can specify various folders as a source.

2. Allow multiple plugin instances

e.g. in vite's configuration allow to create multiple instances. Each instance would be responsible for its own set of icons.

{
    plugins: [
        vitePluginSvgComponent({
            iconDir: path.resolve(__dirname, './node_modules/my-icons'),
            svgSpriteDomId: "svg_sprite__dom_1",
            componentName: "SvgIcon1"
            }
        }),
        vitePluginSvgComponent({
            iconDir: path.resolve(__dirname, './src/local-icons'),
            svgSpriteDomId: "svg_sprite__dom_2",
            componentName: "SvgIcon2"
            }
        })
    ]
}

However, the issue with this approach is to genererate d.ts file.

Please, let me know if you need any further assistance or clarification.

Thanks, I really appreciate your work)

Jevon617 commented 1 year ago

@voknelis Thanks for your Proposition.

I will do it as soon as possible.

Jevon617 commented 1 year ago

@voknelis iconDir supports array at v0.7.5.

voknelis commented 1 year ago

@Jevon617 Thanks a lot!