Extract the dialog box into the @workadventure/npc-dialog-box package - #4
Open
moufmouf wants to merge 4 commits into
Open
Extract the dialog box into the @workadventure/npc-dialog-box package#4moufmouf wants to merge 4 commits into
moufmouf wants to merge 4 commits into
Conversation
The dialog box now lives in packages/npc-dialog-box, an npm workspace
consumed by the map exactly like the future standalone package (it will
move to its own repository once published).
The package builds three artifacts (build.mjs, run on install via
prepare):
- dist/api.js: the main-script API (openDialog/closeDialog)
- dist/npc-dialog.html: the dialog page, fully self-contained - the
iframe-side code is bundled and inlined, so the page no longer depends
on the consumer's build to compile it
- dist/vite.js: a Vite plugin that emits npc-dialog.html (stable,
un-hashed name at the dist root, matching the default dialogUrl) plus
optional extra assets, and serves the same files on the dev server, so
dev and production use identical URLs
The map now integrates with one plugin line per Vite config:
npcDialogBox({ assets: ["npc-avatar.png"] }). The wrapper npc-dialog.html
and the rollup input entry are gone from the map project, and the default
avatar moved from the wrapper's <template> to the avatar option.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Lead with what the package does and a screenshot of the result, then go straight to usage. Implementation details and the plugin-less escape hatch are dropped. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The package now lives in its own repository (github.com/workadventure/npc-dialog-box) and is published on npm, so the packages/ workspace is removed and the dependency resolves to the published 0.1.1 release. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
moufmouf
force-pushed
the
npc-dialog-library
branch
from
August 20, 2026 14:41
61611a6 to
dd9f629
Compare
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.
Stacked on #2.
What
The dialog box moves out of the map's
src/intopackages/npc-dialog-box, an npm workspace named@workadventure/npc-dialog-box. The map consumes it exactly like the future published package will be consumed; when it moves to its own GitHub repository, only the workspace wiring in the rootpackage.jsonchanges to a regular version.How the HTML problem is solved
The hard part was shipping
npc-dialog.htmlin the library while getting it into the consumer's Vite build. The answer is twofold:build.mjsbundles the iframe-side code (typewriter UI, styles, player-variable protocol) into a minified IIFE and inlines it into the HTML template.dist/npc-dialog.htmlhas zero build-time dependencies on the consumer.@workadventure/npc-dialog-box/vite): in build itemitFiles the page under the stable namenpc-dialog.htmlat the dist root — exactly whatopenDialog's defaultdialogUrlresolves to relative to the map — and in dev it serves the identical bytes at the same URL via aconfigureServermiddleware. Optionalassets: [...]copies map-specific files (the avatar) alongside.Consumer integration is one line per Vite config:
Consequences for the map
npc-dialog.htmland thenpcDialogrollup input entry are gone; the wrapper page and itsiframe_api.jsreferrer-loader now live in the package template.<template>trick is gone: the map passesavatar: "npc-avatar.png"toopenDialoginstead.preparebuilds the package onnpm install, so CI (npm install && npm run buildmap) keeps working unchanged.@workadventure/npc-dialog-box/npc-dialog.htmlexport + thedialogUrloption) for setups that can't use the plugin.Testing
npm installbuilds the workspace package;tscandnpm run buildmappass;dist/containsnpc-dialog.html(self-contained) andnpc-avatar.pngwith stable names./npc-dialog.html(correct content-type) and/npc-avatar.png;/src/main.tsbundling resolves the bare package import.npm run devafter checking out this branch so the dev server picks up the new plugin.🤖 Generated with Claude Code