Create your first plugin
In this guide, you'll build a plugin for Obsidian. If you prefer a video walk-through, check out Create Your Own Obsidian Plugin by Antone Heyward.
Don't develop plugins in your main vault. When you develop a plugin, one mistake can lead to unintentional modifications to your vault. You also risk permanently deleting your vault.
Prerequisites
To complete this guide, you will need:
Step 1 — Download the sample plugin
First, you'll download a working sample plugin that you'll build upon for the remaining steps.
- Browse to the Obsidian Sample Plugin.
- Click Use this template.
- In Repository name, enter the name of your plugin. Obsidian plugins are typically prefixed by
obsidian-
. For example,obsidian-instant-coffee
. - Click Create repository from template.
You've now created your own repository based on the Obsidian sample plugin. Next, you'll download the source code on your local machine.
Browse to the repository you just created.
Click Code, and copy the path to your repository.
Open a terminal and navigate to the vault.
cd path/to/vault/.obsidian/plugins
Download the source code into the plugins folder.
git clone https://github.com/your-username/obsidian-instant-coffee.git
Step 2 — Build the plugin
In this section, you'll build the source code for the plugin.
Navigate into the plugin folder.
cd path/to/vault/.obsidian/plugins/obsidian-instant-coffee
Install dependencies.
- npm
- Yarn
npm install
yarn install
Compile the source code. The following command generates a
main.js
that contains the compiled version of your plugin.- npm
- Yarn
npm run dev
yarn run dev
Step 3 — Enable the plugin
To load a plugin in Obsidian, you first need to enable it.
- Open Preferences in Obsidian.
- In the side menu, click Community plugins.
- Under Installed plugins, enable the Sample Plugin by clicking the toggle button next to it.
You're now running a custom plugin that you've built yourself. Nice! 💪
Though, "Sample Plugin" is probably not the name you had in mind for your plugin. Let's change that.
Step 4 — Update the plugin manifest
In this step, you'll update the manifest to rename the plugin., The plugin manifest, manifest.json
is a file that contains information about your plugin, such as its name and version.
- Open the
obsidian-instant-coffee
directory in a code editor, such as Visual Studio Code. - Open
manifest.json
in your editor. - Change
id
to your plugin ID, for exampleobsidian-instant-coffee
. - Change
name
to the human-friendly name of the plugin, for exampleInstant coffee
. - If you'd like, then update
description
,author
, andauthorUrl
as well.
A plugin is also a Node.js package, which you can configure in the package.json
. You shouldn't need to worry much about it for now. For now, update it to match the properties in the plugin manifest.
- Open
package.json
in your editor. - Change
name
to match theid
inmanifest.json
. - Change
version
to match theversion
inmanifest.json
. - Change
description
to match thedescription
inmanifest.json
. - Restart Obsidian to reload your plugin.
Step 5 — Update the source code
In this step, you'll make a change to the source code and reload the plugin to reflect your change.
Open
main.ts
in your editor.Find the lines of code that adds a ribbon icon.
this.addRibbonIcon('dice', 'Sample Plugin', () => {
new Notice('This is a notice!');
});Change the text for the notice. Feel free to come up with a text of your own.
new Notice('Hello, you!');
Restart Obsidian to reload your plugin.
Click the die icon in the sidebar. Make sure it says "Sample Plugin" when you hover it.
Next steps
You've built your own plugin for Obsidian! 🚀 You can experiment by making further changes to the code to see what it does. From here, you can explore some of the guides to see what your plugin can do.