Skip to content

Commit 897c4c2

Browse files
authored
Html entity bundle optimization (#775)
* feat: automatic browser bundle optimization for HTML entities Bundlers using the `imports` field with `browser` condition (Webpack 5+, Vite, esbuild, Rollup, Parcel) now use DOM-based entity decoding instead of shipping the full ~11KB entity lookup table. Server-side builds retain the O(1) lookup table for performance. * chore: mark generated docs assets as binary for simpler PR reviews * chore: rebuild site * fix: include entities source for bun condition in published package
1 parent fa21868 commit 897c4c2

15 files changed

+1657
-2401
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'markdown-to-jsx': patch
3+
---
4+
5+
Automatic browser bundle optimization via conditional exports. Browser builds now automatically use DOM-based entity decoding (`textarea.innerHTML`) instead of shipping the full ~11KB entity lookup table, reducing gzipped bundle size by ~11KB.
6+
7+
This optimization is automatic for bundlers that support the `imports` field with `browser` condition (Webpack 5+, Vite, esbuild, Rollup, Parcel). No configuration required.
8+
9+
Server-side/Node.js builds retain the full O(1) entity lookup table for maximum performance.
10+
11+
This feature uses the [`imports` field](https://nodejs.org/api/packages.html#subpath-imports) in package.json (supported since Node.js 12.19.0). If your bundler does not recognize this field, update to a newer version or the optimization will be skipped silently.

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs/assets/** binary

bun.lock

Lines changed: 150 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bunup.config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ const common = {
1313
} satisfies DefineConfigItem
1414

1515
export default defineConfig([
16+
// Entities modules - built separately for browser field swapping
17+
{
18+
...common,
19+
name: 'entities',
20+
entry: ['src/entities.generated.ts', 'src/entities.browser.ts'],
21+
outDir: 'dist',
22+
format: ['esm', 'cjs'],
23+
dts: true,
24+
target: 'browser',
25+
},
1626
// Main library build - ESM and CJS (includes index, react, html, markdown, native, solid, and vue entry points)
1727
{
1828
...common,
@@ -29,7 +39,7 @@ export default defineConfig([
2939
outDir: 'dist',
3040
format: ['esm', 'cjs'],
3141
dts: true,
32-
external: ['react', 'react-native', 'solid-js', 'solid-js/h', 'vue'],
42+
external: ['react', 'react-native', 'solid-js', 'solid-js/h', 'vue', '#entities'],
3343
target: 'browser',
3444
},
3545
])

0 commit comments

Comments
 (0)