Getting started with plugins
npm
- npm and node.js
node -v
+ npm -v
npm 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 i
in the plugin folder
- Run
npm run dev
and 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.ts
and start changing things
- Refer to the Obsidian API 10 to understand what you can use
- Use
console.log(object)
or console.log(variable)
to check the state/functioning of your plugin (see debugging below)
- Drag the newly-created
main.js
and manifest.json
files from the plugin folder into Your-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 run sudo npm install -g npm
to update npm )
- Run
npm run dev
and the terminal will re-compile whenever the .ts file has changes saved
- Make some changes in
main.ts
(eg. change console.log('loading plugin')
to console.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 update
in the command line under your repo folder.
- Change
manifest.json
and versions.json