perf(js): externalize deps and split entry points for tree shaking#550
Open
adambrudzynski wants to merge 1 commit into
Open
perf(js): externalize deps and split entry points for tree shaking#550adambrudzynski wants to merge 1 commit into
adambrudzynski wants to merge 1 commit into
Conversation
- Externalize @storyblok/richtext and storyblok-js-client so they are not inlined into the bundle, allowing downstream bundlers to tree shake - Add preserveModules and multiple named entry points (index, api, bridge, editable) mirroring the pattern used in @storyblok/react - Update package.json exports map with sub-path exports for each entry Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Externalizes
@storyblok/richtextandstoryblok-js-clientfrom the@storyblok/jsbundle and splits the package into individual entry points — enabling proper tree shaking and code splitting for downstream bundlers.Problem
@storyblok/jswas shipping as a single monolithic bundle (storyblok-js.mjs) with all dependencies inlined. This meant:storyblok-js-clientand@storyblok/richtextwere bundled twice — once inside@storyblok/jsand again as standalone packagesstoryblokEditable) pulled the entire bundle into the consumer's appSolution
Mirrors the pattern already established in
@storyblok/react, which externalizesreact,react-dom, and@storyblok/jsitself.vite.config.tschanges:@storyblok/richtextandstoryblok-js-clientmarked asexternalpreserveModules: true— each source file gets its own output fileindex,api,bridge,editablepackage.jsonchanges:exportsmap updated with sub-path exports for each entry pointmain/moduleupdated fromstoryblok-js.js→index.js/index.mjsBefore / After
index.mjsapi.mjsbridge.mjseditable.mjsBundle analysis — Next.js application
Before
Huge bundle of
@storyblok/jswhen using only@storyblok/reactand@storyblok/richtextpackagesAfter
Test plan
pnpm build— clean output with externalized imports verifiedpnpm test:unit— 19/19 passingpnpm run test:types— no type errorspnpm test:e2e— 4/4 passingyalc— build succeeds, externals confirmed asimportstatements in output