-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat(icon): review icons bundle #477
Conversation
5fd6326
to
63c3035
Compare
8ae7a76
to
da486e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
d992366
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I think you should wait before merging this PR. We would be testing a solution to async import specific icon |
d992366
to
312257b
Compare
312257b
to
87ce731
Compare
Co-authored-by: Daniele <danielemarostica@users.noreply.github.com>
This reverts commit 98f2c4d.
c53d26f
to
0fe0004
Compare
Hi! Is this PR ready to be merged? |
Description
This PR aims at changing how icons are served and bundled.
The main problem with how icons are handled now is the bundle size: the
<Icon />
component works by accepting the name of the icon which is resolved from a dynamic map that contains all the SVGs of three different icon packs. This approach results in all the SVGs being added to the library bundle, which subsequent bundlers cannot tree shake, given that at runtime any of the values of the aforementioned map could be used (in the bundle of applications using it, the library weights at least 6 MB regardless of the number of used components).To solve this issue, this PR fundamentally changes how the
<Icon />
component works, making it a wrapper that accepts the SVG to render as a React function component. This way we can provide a standard interface while leaving the possibility to load any SVG asset without adding bulk to the bundle size.It follows an example of the usage of the new component.
To still provide the user with a set of "recommended" icons, a new
@mia-platform-internal/console-design-system-react/icons
sub-package has been added to the final NPM package. The package contains the icons from the same three packages that were shipped before (Ant Design, Phosphor, and Feather) as well as a set of Mia-Platform-specific custom icons.To make dynamic import of single icons possible, each icon in the package has its own file (more precisely a set of three files: the esm index, the cjs index and the declarations file).
Therefore, the icon components can be accessed from the package as named imports:
or as dynamic imports:
The icons sub-package can be automatically constructed by launching the
build-icons
script.On top of this, the PR upgrades the
vite-plugin-svgr
dev dependency to the latest major (version4.2.0
).Note that this PR is breaking since it changes the interface of the
<Icon />
component. Migrating, however, is simple enough:Checklist