Page MenuHomePhabricator

Make Codex ESM build tree-shakeable
Open, Needs TriagePublic3 Estimated Story Points

Description

Our ESM build is currently all in one file, which does not support tree shaking with most bundlers. We should instead build the ESM build as many small files that import each other. We could do that by either using Rollup's preserveModules setting, or by setting each component and composable as a build entry point.

The UMD build should stay the same. We only have to make this change to the build for the @wikimedia/codex package, not the @wikimedia/codex-search package.

Relevant link for the exact changes that may need to happen: https://www.carlrippon.com/how-to-make-your-react-component-library-tree-shakeable/

Event Timeline

Catrope renamed this task from Make Codex build tree-shakeable to Make Codex ESM build tree-shakeable.Sep 6 2023, 4:38 AM

Some work in this area has already been done as part of https://gerrit.wikimedia.org/r/c/design/codex/+/943652 and its follow-up patch.

The UMD build should stay the same. We only have to make this change to the build for the @wikimedia/codex package, not the @wikimedia/codex-search package.

Should we continue offering a build in this format? I'm not aware of anyone using it. I think that some of the more recent build optimizations (like in the linked patch above) are not compatible with UMD output, so it may be easier to proceed here if we simply drop it.

CJS for MediaWiki (including userscripts) and ESM for everywhere else seems sufficient to me.

I think we need it at least as a transitional measure for MediaWiki. If we split the CJS build into small files, we will no longer have a build with the whole library in one file, and MediaWiki will continue to need that until T344386 is done.

We could build a single-file CJS version of Codex alongside the single-file UMD one.

We could build a single-file CJS version of Codex alongside the single-file UMD one.

Sure, that would be fine too.

This task does not actually connect to the current work around code splitting Codex inside of MediaWiki, because MediaWiki will only rely on the CJS build.

We should still do this but it can happen in the future.

CCiufo-WMF lowered the priority of this task from High to Low.Sep 29 2023, 4:15 PM
CCiufo-WMF moved this task from Needs Refinement to Up Next on the Design-System-Team board.
egardner raised the priority of this task from Low to Needs Triage.Oct 2 2023, 6:53 PM
egardner moved this task from Up Next to Backlog on the Design-System-Team board.