Skip to content

Build: Bundle as ES modules and compile to ES2020 - #521

Open
kepano wants to merge 3 commits into
pr/5-hidden-maincontent-scoringfrom
pr/6-bundle-size
Open

kepano wants to merge 3 commits into
pr/5-hidden-maincontent-scoringfrom
pr/6-bundle-size

Conversation

@kepano

@kepano kepano commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Stacked on #520.

The core bundle goes from 98.2 to 88.4 KB gzipped and the full bundle from 216.0 to 205.3 KB, with identical output.

Both changes are in how webpack.config.js compiles TypeScript:

  • ts-loader emits ES modules instead of CommonJS, so webpack can drop unused exports and hoist modules into one scope: −4.6 KB core, −5.0 KB full. With ES modules, the lazy require('mathml-to-latex') in src/markdown.ts made the full bundle 16 KB larger, so it's a static import now. defuddle/node and the Worker load mathml-to-latex on import instead of on first use.
  • The bundles compile to ES2020 instead of ES6, so optional chaining, ??, classes, async functions and spread stay as written: −5.3 KB core, −5.7 KB full. The bundles then need Chrome 80, Firefox 74, Safari 13.1 or Node 14. The Web Clipper already requires newer (Firefox 113 and Manifest V3).

The budgets go down to 90 and 207 KB, so later growth shows up.

Output is byte-identical to #520 for all 250 fixtures, at each fixture's own URL and at https://example.com/page, with no options, separateMarkdown and markdown, under linkedom and JSDOM (1,500 runs each). tsc --noEmit, lint:unused, lint:innerhtml, npm run size and both Vitest suites pass. Those run the TypeScript source, so I also ran every fixture through the built UMD bundles (the full bundle with the three option sets, the core bundle with none, 2,000 runs per DOM), and the output matches #520's bundles. That check gives the bundles JSDOM's window, document and DOMParser; I haven't run them in a real browser or happy-dom.

With ES modules alone, the lazy require() of mathml-to-latex in
markdown.ts made the full bundle 16 KB larger, so it's a static import
now. defuddle/node loads mathml-to-latex on import instead of on first
use.

Core bundle: -4.6 KB gzipped. Full bundle: -5.0 KB.
ES2020 keeps optional chaining, nullish coalescing, classes, async
functions and spread as written instead of transpiling them. The
bundles then need Chrome 80, Firefox 74 or Safari 13.1 or newer.

Core bundle: -5.3 KB gzipped. Full bundle: -5.7 KB.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant