A comprehensive toolkit for developing Figma plugins
- Initialize a new Figma plugin using a template
- Build your plugin, with support for multiple menu commands that each have their own UI implementation
- Utility functions for common plugin operations
- A library of Preact components that replicate the Figma UI design
To start, read the Figma plugin basics doc to understand how a Figma plugin actually works, and to learn about what’s currently possible (and not possible) in a Figma plugin.
First:
$ npx create-figma-plugin figma-hello-world --yes
Then:
$ cd figma-hello-world
$ ls -a
.gitignore README.md node_modules package-lock.json package.json tsconfig.json src
$ ls src
main.ts
src/main.ts
is the main entry point for our plugin:
// src/main.ts
export default function () {
figma.closePlugin('Hello, World!')
}
See that in package.json
, we’re pointing to src/main.ts
on the "main"
key under "figma-plugin"
:
{
...
"figma-plugin": {
...
"name": "Hello World",
+ "main": "src/main.ts"
}
}
(This example only scratches the surface of what this toolkit provides. See the recipes section below, or jump to the ones for adding a UI to a plugin command, or specifying multiple commands in the plugin sub-menu.)
In package.json
, we also have build
and watch
scripts set up to invoke the build-figma-plugin
CLI:
{
...
"scripts": {
+ "build": "build-figma-plugin",
+ "watch": "build-figma-plugin --watch"
},
...
}
To build the plugin:
$ npm run build
This will generate a manifest.json
file and a build/
directory containing a JavaScript bundle for the plugin.
To watch for code changes and rebuild the plugin automatically:
$ npm run watch
In the Figma desktop app:
- Open a Figma document.
- Go to
Plugins
→Development
→New Plugin…
. - Click the
Click to choose a manifest.json file
box, and select themanifest.json
file that was generated.
Use console.log
statements to inspect values in your code.
To open the developer console in the Figma desktop app, go to Plugins
→ Development
→ Open Console
.
- Specifying multiple commands in the plugin sub-menu
- Adding a UI to a plugin command
- Passing data between the plugin command’s main and UI contexts
- Configuring relaunch buttons
- Customizing the underlying Webpack configuration
Create Figma Plugin’s configuration API is heavily inspired by skpm
’s.