Skip to content

Minify embedded frame bundle for readable srcdoc - #50

Merged
Andrey Skladchikov (andrey-skl) merged 2 commits into
masterfrom
srcdoc-readability
May 11, 2026
Merged

Minify embedded frame bundle for readable srcdoc#50
Andrey Skladchikov (andrey-skl) merged 2 commits into
masterfrom
srcdoc-readability

Conversation

@andrey-skl

Copy link
Copy Markdown
Collaborator

Summary

  • Replace abandoned compile-code-loader with val-loader + an in-memory webpack child compile in mode: 'production'. The embedded frame bundle drops from ~17 KiB unminified to ~4.4 KiB on a single line.
  • Flatten BaseOptions.frameContent and remove \n from _prepareFrameContent injection points so the final iframe srcdoc attribute renders as one line in DevTools.
  • Switch test assertion from minified-away symbol TYPE_SET_INTERFACE to its inlined value set-interface.

Closes #45.

Why val-loader

compile-code-loader is unmaintained (~8 years), relies on webpack-v4 internals (SingleEntryPlugin), and only emitted a development-mode bundle. val-loader is the canonical webpack-5 way to "execute a module at build time and embed its output", so the frame bundle is now produced by a real production-mode webpack compile (terser minification + IIFE).

Files

  • lib/frame-bundle.js — new val-loader entry; runs webpack on frame.ts with memfs, returns the minified bundle string.
  • lib/websandbox.ts — import path swapped to val-loader!./frame-bundle.js; BaseOptions.frameContent and injection helpers single-lined.
  • eslint.config.mjs — file-scoped override (node globals, CommonJS, allow require) for lib/frame-bundle.js.
  • test/sandbox.test.js — assertion updated to runtime value, no semantic change.
  • package.json / package-lock.json — drop compile-code-loader, add val-loader + memfs.

Test plan

  • npm test — 46/46 karma tests green.
  • npm run lint — clean.
  • npm run build — produces dist/websandbox.js; embedded bundle is 4424 bytes, 0 newlines.
  • npm run build-examples + browser smoke: simple.html sandbox initialises, host ↔ sandbox round-trip works, DevTools shows srcdoc on one line.

Replace abandoned `compile-code-loader` with `val-loader`, running a
production-mode webpack child compile of `lib/frame.ts` through an
in-memory filesystem. Terser collapses the bundle to one line and ~4 KiB,
so the iframe `srcdoc` attribute is now navigable in DevTools.

Also flatten the `BaseOptions.frameContent` template and drop the `\n`
injection points in `_prepareFrameContent` so the final srcdoc renders
on a single line.

Test assertion `TYPE_SET_INTERFACE` switched to the inlined runtime
value `set-interface` (terser inlines the `const`).

Closes #45
@andrey-skl

Andrey Skladchikov (andrey-skl) commented May 11, 2026

Copy link
Copy Markdown
Collaborator Author

Before:
Screenshot 2026-05-11 at 17 10 44

After:
Screenshot 2026-05-11 at 19 35 21

@andrey-skl
Andrey Skladchikov (andrey-skl) merged commit 02a96f6 into master May 11, 2026
1 check passed
@andrey-skl
Andrey Skladchikov (andrey-skl) deleted the srcdoc-readability branch May 11, 2026 20:53
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.

Improve DOM readability of embedded widgets

2 participants