Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to customize export #6

Open
jods4 opened this issue May 9, 2021 · 2 comments
Open

Option to customize export #6

jods4 opened this issue May 9, 2021 · 2 comments

Comments

@jods4
Copy link

jods4 commented May 9, 2021

Nice SVG plugin!
Do you think you could add an option so that the module template could be changed?

In my case I'd like to export a ready-to-use Vue component, with a few bells and whistles attached, instead of just the SVD id.

Maybe a moduleTemplate(symbol: string, id: string) option with the current template as default value?

const options = {
   moduleTemplate(symbol, id) {
     return `import addSymbol from 'vite-plugin-svg-sprite/es/runtime';
        addSymbol(${symbol}, ${id});
        export default ${id};`
   }
}
@meowtec
Copy link
Owner

meowtec commented May 10, 2021

It could be:

const options = {
   moduleTemplate({
     symbol, id, codeAddSymbol
   }) {
     return `${codeAddSymbol};
        export default ${id};`
   }
}

addSymbol is an internal function and should not be exposed to users.

@jods4
Copy link
Author

jods4 commented May 10, 2021

The tricky part is making sure import are in the right position (I need to add some) but that would work as well.

This is an advanced scenario that's only present in one place (your build definition), so I wouldn't mind if I had to rewrite the template slightly after a major release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants