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
Issue with unplugin-icons with storybook / builder-vite #419
Comments
Hi, thanks. Can you put together a small reproduction repo that we can experiment with? Also, does it change anything if you add the |
One workaround I've discovered so far is to use the "Raw" mode for the compiler setting
async viteFinal(config, options) {
// return the customized config
let mergedConfig = mergeConfig(config, {
// customize the Vite config here
plugins: [
Icons({
defaultStyle: '',
defaultClass: '',
compiler: 'raw',
}),
],
})
return mergedConfig
},
<script lang="ts">
import RawMdiAlarmOff from '~icons/mdi/alarm-off?raw&width=4em&height=4em'
</script>
{@html RawMdiAlarmOff} Will look at creating an example repo for the above issue |
For info I was able to load the Icon plugin before the others by reversing the order for the mergeConfig function I'm not sure but I'm wondering if the issue might be within sveltedoc-parser, since we're effectively adding in virtual svelte components that don't actually exist on disk async viteFinal(config, options) {
// return the customized config
let mergedConfig = mergeConfig( {
// customize the Vite config here
plugins: [
Icons({
defaultStyle: '',
defaultClass: '',
compiler: 'svelte',
}),
],
resolve: {
alias: _alias.alias_vite_setts,
},
}, config)
console.log(mergedConfig)
return mergedConfig
}, |
I tried to create a reproduction, but I failed, since it was just working with the template (see here for a working example: https://github.com/Amerlander/storybook-experimental-vite-unplugin-icons-issue-repro ). I have a project where I use the latest version of SvelteKit, and it is also working there. I initial had a different async viteFinal(config, { configType }) {
const { config: userConfig } = await loadConfigFromFile(
path.resolve(__dirname, "../vite.config.js")
);
// Remove Svelte plugins that would duplicate those added by the Storybook plugin
const plugins = userConfig.plugins.flat(1)
.filter(p => !p.name.startsWith('vite-plugin-svelte') || p.name === 'vite-plugin-svelte-kit');
return mergeConfig(config, {
...userConfig,
plugins
});
} <!-- Icon.svelte -->
<script>
import SvelteLogo from '~icons/logos/svelte-icon'
</script>
<SvelteLogo />
<br>
<SvelteLogo width="64" height="64"/> // Icon.stories.js
import Icon from '../lib/Icon.svelte';
// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
// More on argTypes: https://storybook.js.org/docs/svelte/api/argtypes
export default {
title: 'Example/Icon',
component: Icon,
};
// More on component templates: https://storybook.js.org/docs/svelte/writing-stories/introduction#using-args
const Template = (args) => ({
Component: Icon,
props: args
});
// More on args: https://storybook.js.org/docs/svelte/writing-stories/args
export const Primary = Template.bind({});
Primary.args = {}; |
I've moved away from svelte now, so I'll close this down if its working ok |
related storybookjs/storybook#20562 |
What version of
vite
are you using?2.9.12
System info and storybook versions
Describe the Bug
Hi,
I've noticed an issue when using unplugin-icons with storybook / builder-vite
Typically the svelte-docgen plugin which builder-vite adds in automatically throws an error
From what I can gather this is because of the way unplugin-icons is used in svelte in that it adds in it's own virtual alias
.storybook/main.cjs
IconTest1.svelte
You can actually use virtual:icons or ~icons for the alias, but svelte-docgen doesn't seem to like it since it's resolved as part of a different plugin
Link to Minimal Reproducible Example
No response
Participation
The text was updated successfully, but these errors were encountered: