A lightning-fast boilerplate for building Figma Plugins in Svelte, React, or Vue built on Vite + TypeScript + Sass
Huge thanks to our backers who have made this project possible!
Founding backers have made substantial contribution to the project at the start which has made this project possible.
...
Feature backers have sponsored individual features that have made this project better for the whole community.
...
If you're interested in supporting this open-source project, please contact the Hyper Brew team.
If you have questions with getting started using Bolt Figma, feel free to ask and discuss in our free Discord community Discord Community.
If your team is interested in paid consulting or development with Bolt Figma, please contact the Hyper Brew team. More info on our Custom Plugin Development & Consulting Services
Yes! Bolt Figma is 100% free and open source, being released under the MIT license with no attribution required. This means you are free to use it in your free or commercial projects.
We would greatly appreciate it if you could provide a link back to this tool's info page in your product's site or about page:
Bolt Figma Info Page Link: https://hyperbrew.co/resources/bolt-figma
Built with Bolt Figma button graphics:
PNG Files
SVG Files
Create your new Bolt Figma project (follow CLI prompts)
yarn create bolt-figma
npx create-bolt-figma
pnpm create-bolt-figma
Change directory to the new project
cd project
Install Dependencies (if not already done by create command)
yarn
npm i
pnpm i
Build the plugin (must run before dev
, can also run after for panel to work statically without the process)
yarn build
npm run build
pnpm build
Run the plugin in hot reload mode for development
Note: Ensure "Hot reload plugin" is checked in Figma Plugin Development menu
yarn dev
npm run dev
pnpm dev
Bundles your plugin and specified assets from copyZipAssets
to a zip archive in the ./zip
folder
yarn zip
npm run zip
pnpm zip
Write frontend UI code in src/main.svelte
Write backend figma code in src-code/code.ts
manifest.json
file in the dist
folderFigma Menu > Plugins > Development > "Your Plugin"
Figma Menu > Plugins > Development > Hot Reloading Plugin
Figma Menu > Plugins > Development > Show/Hide Console
Bolt Figma makes messaging between the frontend UI and backend code layers simple and type-safe. This can be done with listenTS()
and dispatchTS()
.
Using this method accounts for:
once
is set to true)export type EventTS = {
myCustomEvent: {
oneValue: string,
anotherValue: number,
},
// [... other events]
};
Backend Listener: src-code/code.ts
import { listenTS } from "./utils/code-utils";
listenTS("myCustomEvent", (data) => {
console.log("oneValue is", data.oneValue);
console.log("anotherValue is", data.anotherValue);
});
Frontend Dispatcher: index.svelte
or index.tsx
or index.vue
import { dispatchTS } from "./utils/utils";
dispatchTS("myCustomEvent", { oneValue: "name", anotherValue: 20 });
Frontend Listener: index.svelte
or index.tsx
or index.vue
import { listenTS } from "./utils/utils";
listenTS(
"myCustomEvent",
(data) => {
console.log("oneValue is", data.oneValue);
console.log("anotherValue is", data.anotherValue);
},
true,
);
Note: true
is passed as the 3rd argument which means the listener will only listen once and then be removed. Set this to true to avoid duplicate events if you only intend to recieve one reponse per function.
Backend Dispatcher: src-code/code.ts
import { dispatchTS } from "./utils/code-utils";
dispatchTS("myCustomEvent", { oneValue: "name", anotherValue: 20 });
Frontend code is built to the .tmp
directory temporarily and then copied to the dist
folder for final. This is done to avoid Figma throwing plugin errors with editing files directly in the dist
folder.
The frontend code (JS, CSS, HTML) is bundled into a single index.html
file and all assets are inlined.
The backend code is bundled into a single code.js
file.
Finally the manifest.json
is generated from the figma.config.ts
file with type-safety. This is configured when running yarn create bolt-figma
, but you can make additional modifications to the figma.config.ts
file after initialization.
Use the built-in Vite env var MODE to determine this:
const mode = import.meta.env.MODE; // 'dev' or 'production'
Figma requires the entire frontend code to be wrapped into a single HTML file. For this reason, bundling external images, svgs, and other assets is not possible.
The solution to this is to inline all assets. Vite is already setup to inline most asset types it understands such as JPG, PNG, SVG, and more, however if the file type you're trying to inline doesn't work, you may need to add it to the assetsInclude array in the vite config:
More Info: https://vitejs.dev/config/shared-options.html#assetsinclude
Additionally, you may be able to import the file as a raw string, and then use that data inline in your component using the ?raw
suffix.
For example:
import icon from "./assets/icon.svg?raw";
and then use that data inline in your component:
// Svelte
{@html icon}
// React
<div dangerouslySetInnerHTML={{ __html: icon }}></div>
// Vue
<div v-html="icon"></div>