Cleanup sprites (removing unused assets from bundle) #2446
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This reduces the bundle size by about 400KB.
I moved several large SVG illustrations out of Sprites.js and into separate SVG files. These illustrations are mostly used in a single place (or not at all). By extracting them from Sprites.js and putting them in their own files, I was able to load them on demand (as
<img src={...}>
elements) rather than inlining them in the main JS bundle.I also changed a couple of places where existing illustrations were being imported as
import { ReactComponent as MyImage } from "./path/to/myimage.svg"
, preferring to instead doimport myImage from "./path/to/myimage.svg"
. The difference between these is that the former causes Webpack to generate a React component for the SVG and include it in the bundle, whereas the latter just makes a hyperlink to the SVG. The former should mostly be avoided, especially for illustrations that are used on a single page or in a single modal, and can be loaded on demand when they're displayed rather than delaying the download of the initial bundle.