Dependencies
A template can use npm packages, such as a map or chart library (included in the contract-1 baseline):
- Add the package to
dependenciesintemplate/package.json(create it if needed). Do not runnpm installintemplate/. - Import the package as usual:
import maplibregl from 'maplibre-gl', and its CSS withimport 'maplibre-gl/dist/maplibre-gl.css'. - Rebuild: an agent calls the
rebuild_dependenciestool; in the app, choose Templates → Rebuild Template Dependencies; in an ImageFlow source checkout, runnode scripts/rebuild-template-dependencies.mjs /path/to/template. ImageFlow installs the packages with the npm on your Mac (install Node.js if you have none) into its own cache outside the book, keyed bypackage.jsonandpackage-lock.jsonso an unchanged set is reused at once, and writes npm's updatedpackage-lock.jsonback. Install scripts do not run, andfile:dependencies, such as a package intemplate/packages/, install from the same folders. Since no build step runs, such a package can pointmainandtypesat its TypeScript source ("main": "src/index.ts", "types": "src/index.ts"): the rebuild compiles it while bundling and saves the source as its declarations. A package that names a built entry, such asdist/index.js, must keep that output in the template; when an entry is missing, the rebuild stops and says which. It then bundles every package the template imports intotemplate/vendor/:modules/(ES modules, shared code split into chunks, CSS beside them),types/(the declarations those packages reach, intypes/packages/by package name, so.gitignorerules fornode_moduleskeep them),LICENSES/andmanifest.json(packages and versions, the lockfile's hash, and which import maps to which module).
A book never contains installed packages, so it stays small: a template/node_modules folder from before is not used, and the Book check says so; Rebuild Template Dependencies offers to move it to the Trash. Books never read node_modules: book revisions, the folder watcher and Save a Copy skip it. Opening, previews, the Book check and export resolve package imports only through vendor/manifest.json, so a book renders the same code on every Mac, and the template hash, which covers vendor/ but not node_modules/, identifies that code. A package import missing from the manifest is a compile error pointing at the rebuild, and so is a relative import into node_modules/ (or a dot folder), which the template hash and copies leave out. When package-lock.json changes after a rebuild, the Book check warns (template-dependencies) and the book keeps the saved bundle until you rebuild. Exported templates and the library include vendor/ and leave out node_modules/.
- React is the app's: packages that import
reactget the host's React and its hooks. React components from packages, includingmemoandforwardRefcomponents such as react-map-gl's<Map>, are valid JSX in templates and type-check with their props. Bundlingreact,react-domorimageflowis refused. - Types: the rebuild resolves each import as written, subpaths included, through the package's
exports(typesconditions),typesandtypesVersions, then its@typespackage, and copies the declarations it reaches intovendor/types, including those of linkedfile:dependencies. The type check resolves bare imports among those copies as it would innode_modules, socheck_bookwithtypescript: trueworks withoutnode_modulesand without hand-written forwarding declarations; problems inside third-party declarations are not reported.manifest.jsonrecords each typed import's declaration entry undertypes. An import without declarations is typed asany, with atemplate-dependencieswarning. The rebuild also maps each import, and every subpath a vendored package exports with declarations (so imports used only for types, or by other packages' declarations, resolve too), to its entry inpathsoftemplate/tsconfig.json(with avendor/typesfallback) and excludesvendor/there, so code editors and a standalonetscsee the same declarations as the book's check. Whentsconfig.jsonextends the generated.imageflow-sdk/tsconfig.json, the rebuild carries that file'spathsandfilesover, since TypeScript would otherwise drop them, and the app's rebuild first refreshes.imageflow-sdk/from the installed app. - Purity still applies: a library may run freely in an element editor. In a layout, asynchronous or GPU work such as drawing a map runs inside a
<RenderedImage>;renderitself stays synchronous (Render function). - Stylesheets: a package's CSS is bundled with the template's own, and inline
data:images in it stay inline. - Licences:
vendor/LICENSES/holds each bundled package's licence file. Keep it when you share the template.
Rebuilding explicitly in the app or through MCP also refreshes the book's generated .imageflow-sdk/ and .claude/skills/imageflow-templates/ from the installed app, including removal of obsolete generated references. These folders are generated tooling; keep personal instructions elsewhere. Opening a book does not rewrite them. After updating ImageFlow, rebuild once to update local editor types and agent guidance; MCP reference topics always come from the installed app.