Commit 76a7876
authored
feat(superdoc): ship IIFE CDN bundle with working vanilla example (#2835)
* feat(superdoc): ship IIFE CDN bundle with working vanilla example
Switch the CDN-facing build from UMD to IIFE, minify it, expose
`window.SuperDoc` as the class directly, and verify end-to-end with a
real DOCX rendering in the existing CDN example.
- Rename vite.config.umd.js to vite.config.cdn.js; format=iife,
name=SuperDoc, esbuild minify. Bundle drops from 8.8 MB unminified to
4.9 MB minified (1.46 MB gzipped).
- Add src/cdn-entry.js so `window.SuperDoc` is the constructor and named
exports attach as static properties (Quill pattern).
- Inline yjs + hocuspocus into the IIFE (ESM-only — can't be loaded as
script-tag globals). pdfjs-dist stays external; PDF viewing is
documented as ESM + import-map only.
- Flip package.json "main" from the fat UMD to the proper CJS build,
add ./global subpath export plus unpkg/jsdelivr fields. Keep
superdoc.umd.js for one minor cycle as a deprecation-warning shim via
scripts/emit-umd-alias.cjs; removal scheduled for 2.0.
- Extend scripts/audit-bundle.cjs with size budgets (global.js 5/6 MB,
es.js 3/4 MB, style.css 150/200 KB).
- Rework examples/getting-started/cdn/ to load the locally built bundle
via a prepare step, auto-mount a bundled test_file.docx, and include
jsdelivr snippets in the README.
- Rename tests/umd-smoke -> tests/cdn-smoke; add a second HTML page +
Playwright test asserting the deprecation warning fires on the old
filename. Extend examples/__tests__/smoke.spec.ts with cdn-specific
assertions (window.SuperDoc shape, real DOCX renders content).
- Add CDN quickstart to packages/superdoc/AGENTS.md with script-tag and
ESM + import-map copy-paste blocks and SRI guidance.
* refactor(superdoc): drop UMD deprecation shim
The old superdoc.umd.js was broken for browser use (wrong external
globals, ReferenceError on load). No deprecation window needed for
something that didn't work. Remove emit-umd-alias.cjs, the UMD alias
test, and the build:cdn pipe to it. Fix AGENTS.md to note that Yjs is
inlined (only pdfjs-dist stays external).
* docs: switch CDN examples to superdoc.global.js
Update docs to use the new global bundle:
- Live <SuperDocEditor> and <DocCounter> components (embedded in
Mintlify pages) now load superdoc.global.js and use window.SuperDoc
instead of the removed SuperDocLibrary namespace.
- vanilla-js.mdx and quickstart.mdx lead with the <script> tag
approach; ES modules + import map kept as the secondary option.
- Swap unpkg URLs for jsdelivr.
* refactor(superdoc): rename superdoc.global.js to superdoc.min.js
The `.global.js` suffix was borrowed from Vue's build convention, but
SuperDoc is framework-agnostic to consumers — we shouldn't default
internal conventions to Vue. `.min.js` is the widely-understood name
used by Quill, TinyMCE, lodash, jQuery, and Three.js.
- Rename output file and all references across vite config, audit
script, package.json exports (including ./min subpath), smoke tests,
CDN example, AGENTS.md, and live docs components.
- Tidy `loadSuperDocLibrary` -> `loadSuperDoc` in the live Mintlify
SuperDocEditor component.
* fix(superdoc): address review feedback on CDN bundle
Round-1 review surfaced one blocker and several real issues. All
verified before changing.
Blocker:
- Regenerate pnpm-lock.yaml — the cdn-smoke rename left the lockfile
pointing at the old umd-smoke entry, so `pnpm install --frozen-lockfile`
failed in CI before the build step.
Smoke test was a false-positive engine:
- `tests/cdn-smoke/index.html` set `__SUPERDOC_READY__` synchronously
on the line after `new SuperDoc(...)`, so async init failures still
passed the test. Move the flag into `onReady` and switch the test to
`page.waitForFunction`, matching the CDN-example pattern.
- Strengthen the CDN example assertion to check for "Lorem ipsum" from
the bundled sample DOCX, so editor chrome alone can't satisfy it.
Docs / packaging cleanup:
- Drop the `./min` and `./min.js` subpath exports from package.json —
they advertised an IIFE as an importable module, but `require()`
returns `{}`. The `unpkg`/`jsdelivr` fields cover real CDN delivery.
- Replace `@1.27` pins (the package is at 1.26.0) with `@latest` in
AGENTS.md and the cdn example README; document version pinning in
the production-pinning section instead.
- Make Quickstart "Mount the editor" step tab-aware so a CDN reader
doesn't fall into a `<script type="module">` snippet they can't run.
- Update apps/docs/README.md and root `dev:docs` script — both still
referenced the removed `watch:umd` / UMD wording.
Hardening:
- Audit-bundle now fails loudly if `superdoc.min.js`, `superdoc.es.js`,
or `style.css` is missing after a full build instead of silently
skipping the size check.
- prepare.mjs leads with the fix command before the missing-file list,
drops the dead `mkdirSync` guard.
* fix(superdoc): rename cdn example prepare→setup to avoid pnpm lifecycle hook
`prepare` is a reserved npm/pnpm lifecycle script — it auto-runs after
every `pnpm install`. The cdn example's `prepare` copies built artifacts
from `packages/superdoc/dist/`, but those don't exist at install time on
a fresh clone (or in CI before the build step), so install fails with
exit 1 before anything can build.
Rename to `setup` so it only runs when explicitly invoked by `pnpm dev`
or the Playwright config.
* fix(superdoc): invoke cdn example setup via node directly
The CI `getting-started` job restores a cached workspace but doesn't
install pnpm on PATH, so Playwright's webServer command
`pnpm --dir ... run setup` exits with "pnpm: not found". Other examples
avoid this because their runner falls back to `npm run --prefix` when
local node_modules exist.
Call `node setup.mjs` directly — no package manager dependency, no
script-name coupling, works identically in dev and CI.
* fix(superdoc): don't fail audit-bundle on partial builds
The missing-file gate I added in round-2 of review broke the SDK
validation pipeline, which runs `build:es` (producing superdoc.es.js
only, not superdoc.min.js). The gate assumed "es.js present = full
build, so min.js must exist too" — wrong.
`build:cdn` fails loudly on its own if the CDN bundle is broken, so a
second gate here was double-counting. Revert to the plain `continue`
behaviour for missing files. Size budgets still enforce hard failures
when files ARE present and too big.
* test(superdoc): unit test cdn-entry namespace attachment
Codecov flagged src/cdn-entry.js as 0% covered because its only
exercisers are the Playwright smoke tests, which Codecov doesn't see.
The round-1 review also asked for a direct test of the attach loop —
if a named export silently drops due to a Function intrinsic
collision, the smoke test's spot-checks (createTheme, DOCX) wouldn't
catch an unrelated export going missing.
Three checks: default export is the SuperDoc constructor, every
non-default/non-SuperDoc named export from index.js lands on the
class as a static property, and Function intrinsics (name, prototype)
aren't clobbered.
* fix: update demos and tighten cdn-entry test for round-2 review
Final review flagged three loose ends before merge:
1. In-repo demos still referenced the removed `superdoc.umd.js` and
`window.SuperDocLibrary`. They passed CI because `@latest` on
unpkg/jsDelivr still resolves to the pre-merge 1.26.0 tarball, but
they'd 404 and `ReferenceError` the moment a newer release lands
without those names. Fixed:
- `demos/cdn/index.html` — jsDelivr URL, `<script>` (not module),
`new SuperDoc(...)`.
- `demos/word-addin/server/public/{editor.html,editor.js}` — same
treatment, plus swapped the nonsensical pinned `superdoc@.21.0-next.1`
for the current package alias.
- `demos/chrome-extension/` — replaced the vendored 4.8 MB
`lib/superdoc.umd.js` with a fresh `lib/superdoc.min.js`, updated
manifest + content.js + README to match. All `SuperDocLibrary.*`
calls (and a couple of error strings) now reference `SuperDoc`.
2. `cdn-entry.test.js` was checking `!== undefined` for each attached
static, which a stale wrapper or wrong-identity re-export would
silently pass. Assert `SuperDoc[key] === namespace[key]` instead,
and add a check that `SuperDoc.SuperDoc` / `SuperDoc.default` don't
leak through the attach loop.
3. PR body still claimed the old `superdoc.umd.js` "still works for
now" — that was true when the shim existed; it was dropped in
`91725cd0a`. Updated the PR body separately to reflect the actual
shipped migration story.
* fix(demo): use local build in demos/cdn so smoke test passes pre-release
Pointing the CDN demo at jsDelivr @latest 404s until a superdoc release
containing superdoc.min.js publishes — 1.26.0 only has superdoc.umd.js.
CI's DEMO=cdn smoke test caught this (three console errors from the
missing script and stylesheet).
Mirror the pattern from examples/getting-started/cdn: add setup.mjs
that copies the locally built bundle + style.css into the demo dir,
point index.html at the local copies, and keep the jsDelivr URLs as
an inline comment + in the README as the production recipe.
Verified locally: DEMO=cdn playwright test passes (1/1).1 parent 84b450c commit 76a7876
40 files changed
Lines changed: 1480 additions & 99027 deletions
File tree
- .github/workflows
- apps/docs
- getting-started
- frameworks
- snippets/components
- demos
- cdn
- chrome-extension/chrome-extension
- lib
- word-addin/server/public
- examples
- __tests__
- getting-started/cdn
- packages/superdoc
- scripts
- src
- tests
- cdn-smoke
- umd-smoke
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
175 | 175 | | |
176 | | - | |
| 176 | + | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
179 | 179 | | |
180 | | - | |
| 180 | + | |
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
| 50 | + | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
| |||
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
110 | | - | |
111 | | - | |
112 | | - | |
| 111 | + | |
113 | 112 | | |
114 | 113 | | |
115 | 114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
127 | | - | |
128 | | - | |
| 126 | + | |
129 | 127 | | |
| 128 | + | |
130 | 129 | | |
131 | 130 | | |
132 | 131 | | |
133 | 132 | | |
134 | 133 | | |
135 | | - | |
136 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
137 | 138 | | |
138 | | - | |
139 | | - | |
140 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
141 | 142 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
147 | 161 | | |
148 | 162 | | |
149 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | | - | |
| 98 | + | |
| 99 | + | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | | - | |
| 48 | + | |
| 49 | + | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
6 | 13 | | |
7 | 14 | | |
8 | 15 | | |
| |||
28 | 35 | | |
29 | 36 | | |
30 | 37 | | |
31 | | - | |
| 38 | + | |
32 | 39 | | |
33 | 40 | | |
34 | 41 | | |
| |||
44 | 51 | | |
45 | 52 | | |
46 | 53 | | |
47 | | - | |
| 54 | + | |
48 | 55 | | |
49 | 56 | | |
50 | | - | |
| 57 | + | |
51 | 58 | | |
52 | 59 | | |
53 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
0 commit comments