Quick start
Pre-requisites#
- Node.js – v20
- Figma desktop app
Bootstrapping a new plugin/widget from a template#
$ npx --yes create-figma-plugin
You’ll then be prompted to select from the following templates:
plugin/hello-world
— A plugin without a UI.plugin/preact-rectangles
— A plugin with a UI built using Create Figma Plugin’s Preact component library.plugin/preact-resizable
— A plugin with a resizable UI window.plugin/preact-tailwindcss
— A plugin with a UI that uses Tailwind CSS.plugin/react-editor
— A plugin with a UI that uses a React component.widget/notepad
— A FigJam widget with a UI.
Configuring the plugin/widget#
Configuration options for your plugin/widget go under the "figma-plugin"
key of your package.json
file.
A Figma plugin (eg. plugin/preact-rectangles
) would be configured as follows:
{
"figma-plugin": {
"editorType": [
"figma"
],
// ...
"name": "Rectangles",
"main": "src/main.ts",
"ui": "src/ui.tsx"
}
}
See that:
"main"
is set tosrc/main.ts
, which is the main entry point for the plugin."ui"
is set tosrc/ui.tsx
, which is the plugin’s UI implementation.
A FigJam widget (eg. widget/notepad
) would be configured as follows:
{
"figma-plugin": {
"editorType": [
"figjam"
],
"containsWidget": true,
// ...
"name": "Notepad",
"main": "src/main.tsx",
"ui": "src/ui.tsx"
}
}
Because this is a FigJam widget, see that:
"editorType"
is set tofigjam
."containsWidget"
is set totrue
.
See all the supported configuration options.
Building the plugin/widget#
In the package.json
file, we have build
and watch
scripts set up to invoke the build-figma-plugin
CLI:
{
"scripts": {
"build": "build-figma-plugin --typecheck --minify",
"watch": "build-figma-plugin --typecheck --watch"
}
}
The build-figma-plugin
CLI is powered by esbuild, which enables extremely fast, sub-second builds. When the --typecheck
flag is specified, your TypeScript code will also be compiled and type-checked by the TypeScript compiler.
To build the plugin/widget:
$ npm run build
This will generate a manifest.json
file and a build/
directory containing the JavaScript bundle(s) for the plugin/widget. (To customize the output directory for the manifest.json
and JavaScript bundles, use the --output
flag when invoking the build-figma-plugin
CLI, eg. --output my-plugin
.)
(Configuring your plugin/widget must be done via package.json
. Avoid manually editing the manifest.json
file. Because the manifest.json
file is always regenerated on build, any changes you make will always get overridden.)
To watch for code changes and rebuild the plugin/widget automatically:
$ npm run watch
Learn how to:
- Customize the underlying build configuration used by the
build-figma-plugin
CLI - Modify the
manifest.json
file just before it gets output by thebuild-figma-plugin
CLI
Installing the plugin/widget#
- In the Figma desktop app, open a Figma/FigJam document.
- Search for and run
Import plugin from manifest…
orImport widget from manifest…
via the Quick Actions search bar. - Select the
manifest.json
file that was generated by thebuild
script.
Debugging#
Use console.log
statements to inspect values in your code.
To open the developer console, search for and run Show/Hide Console
via the Quick Actions search bar.
Publishing to Figma Community#
Figma will generate a unique ID for you when you first try to publish your plugin/widget. Copy and paste that ID into the "figma-plugin"
configuration (under the "id"
key), then run the build
script again to regenerate the plugin/widget’s manifest.json
file.
See also#
Official docs and code samples from Figma:
Community:
- Friends of Figma Discord – Join the
#plugin-api
and#widget-api
channels - Twitter List: Figma Society