question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

vite plugin and react dynamic change icon not work

See original GitHub issue

Icon always be static,like follow image Jietu20210408-141518-HD 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 bbb

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JessicaSachscommented, Aug 2, 2021

Ohhh. Now I understand that comment. Honestly, since the iconify runtime causes a FOUC I just switched to using your Vite Icons Plugin. 😅

0reactions
antfucommented, Aug 2, 2021

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found