(posted on Developers and API since this plugin is only useful for developers)
I made this for me, but thought other developers might find it useful:
What it does is that if you have a plugin with a .git directory or a .hotreload file in it, then it will be automatically watched for changes to the main.js or styles.css, and after a debounce period, the target plugin will be reloaded in Obsidian (by first disabling and then re-enabling it).
So instead of having to keep reloading Obsidian or toggling your plugins manually, you can just save and/or rebuild your plugin, and have the update in Obsidian almost instantly.
To install the plugin, just clone the repo (or unpack the .zip release) into your vault’s plugins directory. Then activate it from the “Community Plugins” tab, like any other plugin.
Good ideas! The plugin and its readme have been updated. The plugin now posts a Notice about the reload, so you don’t have to do it in your plugin anymore.
I’m very new to this, it seems that the handler is only fired on changes to config and workspace files within .obsidian directory, so changes in .obsidian/plugins are not monitored. Could you point me to what I’m missing?
I’ve added a console.log(filename); statement as first line in onFileChange to understand what was happening, and then tried to edit and create new files within the vault, both in the main directory, directly in .obsidian directory and in its subfolders - it worked fine for main vault directory, but within .obsidian only config and workspace files got logged.
Ah. That makes sense, actually; I recently found out that on Linux, Obsidian doesn’t do a recursive directory watch: it starts a new watch for each subfolder explicitly. Which kinda sucks because even if hot-reload were to start a watch for /plugins, it would also have to do it for every folder as well.
I’ve updated the plugin (0.1.4) to add Linux support: give it a try and let me know how it works!
Actually, it won’t detect that you’ve created a new plugin unless something triggers it on an old plugin. It also won’t detect when a plugin becomes hot-reloadable. So I’m adding some more code to fix those cases.
This plugin seems interesting, and I will try it now. Just one thing came to my mind, even though this is only meant for developers, could you make it available via the normal community plugin search in Obsidian? You could write something like “FOR DEVELOPERS ONLY” in the description field.