Plugin resources
Plugin resources
Section titled “Plugin resources”A plugin can load files located next to its own module through
ctx.resources:
const data = await ctx.resources.loadJson("data/defaults.json");const text = await ctx.resources.loadText("templates/note.md");const bytes = await ctx.resources.loadBinary("images/logo.png"); // ArrayBufferconst url = await ctx.resources.loadUrl("images/logo.png"); // usable in <img>- Paths are relative to the plugin’s folder. Absolute paths/URLs and any
..escaping that folder are rejected. - Where the folder is depends on how the plugin was installed:
- URL plugin — sibling of the module URL, fetched over HTTP.
- File plugin on desktop — the plugin’s real folder on disk.
- File plugin on the web — the browser cannot see the folder, so each load asks the user to pick the file.
- Built-in plugin — served from
/plugins/<id>/in the app bundle.
- Files in
plugins/<name>/resources/are copied next to the bundle bybun run plugin:build, so they are reachable by their relative path. - Markdown files in
plugins/<name>/skills/are copied toskills/next to the bundle, preserving nested paths, and loaded with the same resource API. - Try it: install
/plugins/clock/index.jsand run Clock: Load bundled JSON data — it readsdata.jsonfrom the same folder.
Documentation under CC BY 4.0 · © SCFlow contributors ·Back to supplychainflow.org