Aller au contenu

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"); // ArrayBuffer
const 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 by bun run plugin:build, so they are reachable by their relative path.
  • Markdown files in plugins/<name>/skills/ are copied to skills/ next to the bundle, preserving nested paths, and loaded with the same resource API.
  • Try it: install /plugins/clock/index.js and run Clock: Load bundled JSON data — it reads data.json from the same folder.

Documentation sous licence CC BY 4.0 · © les contributeurs de SCFlow ·Retour à supplychainflow.org