vite plugin and react dynamic change icon not work
See original GitHub issueIcon always be static,like follow image vite config
PurgeIcons({
// globs for searching source file to analyze
content: ['**/*.html', '**/*.jsx', '**/*.tsx'],
}),
main.tsx
import '@purge-icons/generated';
//...
icon code, always be first icon ‘lightbulb-outline’
<a onClick={toggleTheme}>
{/* always be first icon 'lightbulb-outline' */}
{currentTheme?.name === 'dark-default' ? (
<Icon name="mdi:lightbulb-outline" type="ionify" />
) : (
<Icon name="mdi:lightbulb-on-outline" type="ionify" />
)}
</a>
//......................
const Ionify: FC<IconProps<{ name: string; prefix?: string }>> = (props) => {
const { name, style, classes, iconfont, prefix, ...rest } = useIcon(props);
const iconName = prefix ? `${prefix}:${name}` : name;
return (
<span {...rest} className={classNames(classes)} style={style}>
<span data-icon={iconName} className="iconify" />
</span>
);
};
but antd icon use its own component work fine
<a onClick={toggleTheme}>
{currentTheme?.name === 'dark-default' ? (
<Icon component={() => <PieChartOutlined />} type="antd" />
) : (
<Icon component={() => <DotChartOutlined />} type="antd" />
)}
</a>
// ..............
const AntdIcon: FC<
IconProps<{
component: AntdIconComponent;
twoToneColor?: TwoToneColor;
}>
> = (props) => {
const { component: IconComponent, style, classes, iconfont, ...rest } = useIcon(props);
return <IconComponent {...rest} style={style} className={classNames(classes)} />;
};
export default AntdIcon;
and
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Production build missing fontawesome imports when using ...
Describe the bug Font awesome icons shared across chunk-split boundaries are missing from every import except the first one when importing a ...
Read more >Dynamic SVG component in Vite + React + TS
Once SVGR setup is done we are ready to create the functionality that will grab the icon-name and fetch it from assets and...
Read more >Vite / Rollup Incorrect Chunking - font awesome - Stack Overflow
This feels like a bug with rollups bundler algo to me, as it's creating a chunk for the icon correctly and importing it...
Read more >vite-plugin-favicon - npm
Create and manage favicons for vite bundles, mostily compatible with the config of favicons-webpack-plugin. Latest version: 1.0.8, ...
Read more >Static Asset Handling - Vite
url() references in CSS are handled the same way. If using the Vue plugin, asset references in Vue SFC templates are automatically converted...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ohhh. Now I understand that comment. Honestly, since the iconify runtime causes a FOUC I just switched to using your Vite Icons Plugin. 😅
@JessicaSachs it’s kinda a limitation of how Iconify runtime implemented https://github.com/antfu/purge-icons/issues/17#issuecomment-815498834
you can try to adapt to this component: https://github.com/antfu/antfu.me/blob/master/src/components/Icon.vue