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

Exclude / tree-shake Blueprint icon package dependency #1963

Closed
amcclain opened this issue Jun 12, 2020 · 6 comments
Closed

Exclude / tree-shake Blueprint icon package dependency #1963

amcclain opened this issue Jun 12, 2020 · 6 comments

Comments

@amcclain
Copy link
Member

The Blueprint icons package contributes a fair amount of weight to our builds, but we don't use the icons (at least not deliberately/directly). However the icon package (as a whole) is included as a dependency of blueprintjs/core.

See palantir/blueprint#2193 for webpack based workarounds we should look to implement.

@cnrudd
Copy link
Member

cnrudd commented Jun 26, 2020

@amcclain I've confirmed in my local machine that the suggestions in that issue convo work.
I tried:

            new webpack.NormalModuleReplacementPlugin(
              /.*\/generated\/iconSvgPaths.*/,
              path.resolve(hoistPath, 'static/emptyIconSvgPaths.js'),
            ),

It does reduce the weight of the build, but it did not cut down build time.

Some client apps do use blueprint icons. I know of one app where the dialogs use the blueprint top right close button.
Screen Shot 2020-06-26 at 3 55 03 PM

Is your idea that this should be an option that defaults to useBluePrintIcons = false? And it can be set to true by passing useBluePrintIcons: true into webpack.config.js for an app that needs the icons - or vice-versa?
We could also maybe have that config accept a file path to a file that contains the icon svg code just for the icons the app is using..
Or we could just put into the replacement file the one or two icons that we know are hard to avoid, like the dialog close icon, and the popover arrows.

With Icons Compiled successfully in 1.14m
Screen Shot 2020-06-26 at 3 14 40 PM
Without Icons Compiled successfully in 1.18m
Screen Shot 2020-06-26 at 3 13 53 PM

@cnrudd
Copy link
Member

cnrudd commented Jun 26, 2020

Here are the branches to run locally to see the app without the icons:
Hoist React: https://github.com/xh/hoist-react/tree/noBluePrintIcons
Hoist Dev Utils: https://github.com/xh/hoist-dev-utils/tree/noBluePrintIcons

@amcclain
Copy link
Member Author

Thanks for looking at this!

The use of the BP icon in dialogs is probably common given that we are still using their dialog directly out of kit. If we can get back on the horse with #1809 (I need to help by catching up there!) seems like we could avoid that particular usage.

I think it would make a lot of sense to introduce the change to exclude the icons along with a boolean flag to put them back. I would default that to false so apps pick up the reduction in bundle size automatically, but it would provide a ready-made escape hatch.

If we find apps wanting to include some subset of icons we can look further - although then I would want to understand the use case.

I vote we try to get dialog done to avoid that one very common usage, then make this change.

@cnrudd
Copy link
Member

cnrudd commented Jun 26, 2020

@amcclain Ok, I think other hard to avoid icons are the popover arrows. Popover is a pretty popular component, I think, and it uses icons to make the little pointer arrows.

@amcclain
Copy link
Member Author

Got it, so the other very reasonable seeming option is to inventory the icons we know are used / likely to be used, and create that optimized SVG file with just those ones. That way we're not blocking on the dialog work but could still ~120k (gzipped!) off the builds.

If you have a sense of how that would fit together, would be great to try

@cnrudd
Copy link
Member

cnrudd commented Jun 26, 2020

ok, will put that file together next.

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

No branches or pull requests

2 participants