Getting started with plugins
npm
- npm and node.js
node -v+npm -vnpm init- initialise- you can get modules of code snippets
Getting started
- Download VS Code
- Set up Node.js and NPM
- Looking at simple plugin and cloning it
- Open your terminal
- Open the folder for the newly-downloaded plugin in the terminal
- Run
npm iin the plugin folder - Run
npm run devand the terminal will re-compile whenever the .ts file has changes saved
- Open up the plugin’s folder in VS Code
- Open the file
main.tsand start changing things - Refer to the Obsidian API 10 to understand what you can use
- Hover API elements
- Use
console.log(object)orconsole.log(variable)to check the state/functioning of your plugin (see debugging below) - Drag the newly-created
main.jsandmanifest.jsonfiles from the plugin folder intoYour-Vault/.obsidian/plugins/Some-Plugin-Folder - (If loading the plugin for the first time, reload—or quit and relaunch—Obsidian)
- (Unload and re)load the plugin in Obsidian’s Preferences → Community Plugins → the appropriate plugin toggle
- Test it by invoking the features you’ve played with
- Debug by using the Console tab in Obsidian’s Developer Tools (open dev tools with
cmd/ctrl+shift+i, then select the console tab)
How I got started
- Install VS Code
- Create a new Obsidian test vault
- Clone obsidianmd/obsidian-sample-plugin as a template
- Init a new git repo (Initialise a git repo) at
test-vault/.obsidian/plugins/and pull the created repo in the step before - Install npm and NodeJS – I did via homebrew.
- Run
npm i(I also needed to runsudo npm install -g npmto update npm ) - Run
npm run devand the terminal will re-compile whenever the .ts file has changes saved - Make some changes in
main.ts(eg. changeconsole.log('loading plugin')toconsole.log('loading my awesome plugin') - Changes should automatically compile into
main.js
- Reload Obsidian to load the new version of your plugin.
- Enable plugin in settings window.
- For updates to the Obsidian API
run npm updatein the command line under your repo folder. - Change
manifest.jsonandversions.json