web-stories-wp
web-stories-wp copied to clipboard
Masks: Improve bundle size
Feature Description
The constants.js
file in the masks package is a whopping 300KB large. This also shows in bundle analyzer:

That makes sense, because it contains a ton of clip paths.
I think the way the masks package is structured can be improved though to make this more efficient.
For example, in most places we only use functions like canSupportMultiBorder
, generateMaskId
or simple constants like MaskTypes
The full list of clip paths is only used in the shapes pane in the library:
https://github.com/GoogleForCreators/web-stories-wp/blob/22cf54d030e407f469350f21273f6d1c223aa99b/packages/story-editor/src/components/library/panes/shapes/shapesPane.js#L24
We should be able to improve performance here by reducing the bundle size using the following to steps:
- Create a separate export in the masks package just for the clip paths
- Dynamically import that separate definition in the shapes pane
Alternatives Considered
Additional Context
We should be able to improve performance here by reducing the bundle size using the following to steps:
- Create a separate export in the masks package just for the clip paths
- Dynamically import that separate definition in the shapes pane
That's easier said than done, because utils like getMaskByType()
and getElementMask
obviously rely on MASKS
as well.