1653lin413 downloadsLoad and hot-reload standalone local JavaScript drawer modules from your vault with lifecycle cleanup and secret storage support.
A minimal, zero-dependency microkernel host for Obsidian (1.11.5+, desktop only) that loads and hot-reloads standalone local JavaScript drawer modules (*plugin.js / *plugin.mjs) directly from your vault—no build step required for local modules.
_Modules/plugins by default) are dynamically imported via native ES import() and automatically execute when the host loads or reloads.SecretStore.Runtime): Service registry (register, get, has) with duplicate protection, single-module failure rollback, and LIFO (dispose) cleanup on hot reload or unload.PluginLoader): Scans the configured vault folder (default: _Modules/plugins) for *plugin.js / *plugin.mjs files, strictly loads export default, and busts ESM cache using timestamp queries.SecretStore): Integrates exclusively with Obsidian's built-in SecretStorage (1.11.5+) and SecretComponent. Plaintext keys are never written to data.json, and missing secrets fail fast by returning null.getLanguage() API.Every module receives the runtime instance in setup(runtime) and dispose(runtime), and window.moduleHost also exposes the active runtime for console debugging or standalone scripts:
| Service key | Value |
|---|---|
"app" |
Obsidian App instance |
"plugin" |
ModuleHostPlugin instance |
"obsidian" |
Full "obsidian" API namespace (Notice, Component, Modal, etc.) |
"secrets" |
SecretStore wrapper (get(aliasOrId), list()) |
_Modules/plugins).plugin.js or plugin.mjs, such as _Modules/plugins/helloPlugin.js:let scope = null;
export default {
name: "hello-drawer",
async setup(runtime) {
const app = runtime.get("app");
const hostPlugin = runtime.get("plugin");
const obsidian = runtime.get("obsidian");
// Manage listeners, timers, and UI cleanup via a standalone Component
scope = new obsidian.Component();
scope.load();
const statusEl = hostPlugin.addStatusBarItem();
statusEl.setText("Hello Drawer");
scope.register(() => statusEl.remove());
scope.registerEvent(
app.workspace.on("file-open", (file) => {
if (file) {
statusEl.setText(`Active: ${file.basename}`);
}
})
);
new obsidian.Notice("Hello drawer loaded.");
},
async dispose() {
// One-line cleanup for all listeners, timers, and registered callbacks
scope?.unload();
scope = null;
}
};
热重载所有本地抽屉模块) from the Command Palette whenever you edit a module.Note on commands and custom views:
obsidian.Componentautomatically detaches workspace events, DOM events, and intervals. If your drawer manually registers commands (hostPlugin.addCommand) or customItemViewtypes (hostPlugin.registerView), make sure to remove/unregister them insidedispose(runtime).
DEEPSEEK_API_KEY) and bind it to your secret storage entry—or call secrets.get("my-secret-id") directly with the exact storage ID:const secrets = runtime.get("secrets");
const apiKey = secrets.get("DEEPSEEK_API_KEY"); // returns string | null
if (!apiKey) {
throw new Error("Missing DEEPSEEK_API_KEY in Obsidian secret storage.");
}
While Module Host itself only scans your configured plugins folder (_Modules/plugins) and enforces no directory layout outside it, organizing your _Modules folder into four optional layers keeps AI-assisted local development clean:
_Modules/capabilities/ — Reusable single-domain helper molecules (e.g., vault, text, JSON, canvas wrappers)_Modules/presets/ — Higher-level engines or JSON configs shared across modules_Modules/plugins/ — Resident drawer modules (*plugin.js / *plugin.mjs) scanned by Module Host_Modules/scripts/ — One-off scripts triggered on demand via a launcher modulemain.js and manifest.json from the latest GitHub Release.<YourVault>/.obsidian/plugins/module-host/.npm install
npm run build
Copy the generated main.js and manifest.json into <YourVault>/.obsidian/plugins/module-host/.