Figma Plugin Manifest: The Ultimate JSON Guide
So, you're diving into the world of Figma plugin development, huh? Awesome! One of the first things you'll encounter is the manifest.json file. Think of it as the blueprint for your plugin – it tells Figma everything it needs to know about your creation. This guide will break down each part of the manifest file, making it super easy to understand and get started.
Understanding the Basics of Figma Plugin Manifest
The Figma plugin manifest file, typically named manifest.json, is a crucial component in the development of Figma plugins. It acts as a configuration file that provides Figma with essential information about your plugin. This information includes the plugin's name, entry points, user interface details, and various other settings that define how the plugin interacts with Figma. Without a properly configured manifest.json, Figma won't be able to recognize and run your plugin correctly. So, it's super important to get this right from the start!
Why is manifest.json Important?
The manifest.json file is the cornerstone of your Figma plugin because it tells Figma everything it needs to know about your plugin. Imagine trying to introduce yourself without a name or any defining characteristics – that's what your plugin would be without a well-crafted manifest file! It ensures that Figma can correctly load, display, and execute your plugin, making it an indispensable part of the development process. Think of it as the plugin's identity card, clearly stating its purpose and how it should behave within the Figma environment. Getting this right ensures a smooth and seamless experience for your users.
Structure of manifest.json
The manifest.json file follows a specific JSON structure, which includes several key-value pairs. Each key represents a specific attribute or setting for the plugin, and the corresponding value defines that attribute's value. Understanding this structure is crucial for properly configuring your plugin. The basic structure generally includes fields like name, id, api, main, and ui, among others. These fields collectively define the plugin's identity, how it interacts with Figma's API, and how its user interface is presented. By adhering to this structure, you ensure that Figma can correctly interpret the manifest file and load your plugin without any hiccups.
Key Properties in manifest.json
Let's dive deep into the essential properties you'll find in the manifest.json file. Knowing what each one does will help you customize your plugin exactly how you want it.
name
The name property is pretty straightforward – it's the name of your plugin! This is what users will see in the Figma menu, so make it catchy and descriptive. It should clearly convey what your plugin does. For example, if you’re building a plugin that automatically generates color palettes, you might name it “Color Palette Generator.” Keep it concise and avoid using overly technical terms. A well-chosen name can significantly impact how users perceive and discover your plugin, making it more appealing and user-friendly. Think of it as the first impression your plugin makes!
id
The id is a unique identifier for your plugin. Figma uses this to distinguish your plugin from others. When you publish your plugin, Figma automatically assigns an ID to it. While you're developing locally, you can use a temporary ID, but remember to let Figma handle the final ID assignment when you publish. The ID ensures that Figma can accurately track and manage your plugin, especially when it comes to updates and version control. Without a unique ID, Figma wouldn't be able to differentiate between various plugins, potentially causing conflicts and confusion.
api
The api property specifies the API version that your plugin is using. This is crucial because Figma's API evolves over time, and specifying the correct version ensures that your plugin works as expected. Always check the Figma developer documentation for the latest API version and update your manifest.json accordingly. This ensures compatibility and access to the newest features and improvements. Using the wrong API version can lead to unexpected behavior or even prevent your plugin from functioning correctly.
main
The main property points to the main JavaScript file that contains your plugin's core logic. This is the entry point where Figma starts executing your plugin's code. Ensure that the path specified is correct and that the file exists. The main file typically handles interactions with Figma's API, processes user input, and performs the primary functions of your plugin. It's the brain of your plugin, orchestrating all the operations and functionalities. A properly configured main entry point is essential for your plugin to run seamlessly within Figma.
ui
If your plugin has a user interface, the ui property specifies the HTML file that defines the UI. This file is loaded into a sandboxed iframe within Figma, allowing users to interact with your plugin. The UI typically includes buttons, input fields, and other interactive elements. Make sure the path to your HTML file is correct. The UI is the face of your plugin, providing users with a way to interact with its features and functionalities. A well-designed UI can greatly enhance the user experience and make your plugin more intuitive and user-friendly.
editorType
The editorType property defines in which editor your plugin will work. It could be in figma or figjam or both.
widgetApi
Specifies which API that widget will use. Usually it is 1.0.0.
componentApi
Specifies which component API your plugin will use. This will depend on your manifest version.
parameters
Specify input parameters your command will use.
parameterOnly
Whether this command can only be run with parameters specified.
triggers
Specify trigger events for widgets. They include TIMER, VIEWPORT_BOUNDS_CHANGE, SELECTION_CHANGE, EDIT. They must be defined as array of strings.
menu
The menu property allows you to add your plugin to Figma's menu. You can create submenus and menu items, making it easy for users to find and use your plugin. Each menu item can trigger a specific command or action within your plugin. A well-organized menu can significantly improve the discoverability and usability of your plugin. For example, you might create a main menu item for your plugin and then include several sub-items for different functions.
contextualMenu
The contextualMenu allows you to trigger specific events based on the right click menu.
command
The command property specifies a command that your plugin can execute. This is typically associated with a menu item or a keyboard shortcut. When the command is triggered, your plugin's code is executed. You can define multiple commands in your manifest.json. Commands are the actions that users initiate within your plugin, whether it's generating a design element or applying a specific effect. Properly defining commands is crucial for enabling users to interact with your plugin effectively.
commands
This is an array of commands, where each command has a name, id and handler.
onSelectionChange
Specify what to do when something is selected.
onViewportBoundsChange
Specify what to do when viewport bounds change.
onDrop
Specify what to do when something is dropped.
dropHandlers
An array of functions to be executed on drop.
code
The code property specifies the code to be injected on load.
stylesheet
Specify the css stylesheet for the component.
scripts
Specify the order of execution of the script tags.
style
The style property is the style for the widget. It could contain things like width, height and fill.
previewStyle
The previewStyle property is the style for the widget preview, before it is dropped on the editor.
helpers
This is usually a path to helper functions.
handlers
An array of handlers for the drop.
transformNodesAsync
Specify a function that transforms nodes asynchronously.
createNodesAsync
Specify a function that creates nodes asynchronously.
transformTextAsync
Specify a function that transforms text asynchronously.
createTextAsync
Specify a function that creates text asynchronously.
closePlugin
The closePlugin function allows you to programmatically close your plugin. This can be useful when your plugin has completed its task or when you want to provide a way for users to exit the plugin manually. Closing the plugin ensures that it doesn't continue running in the background, freeing up resources and preventing potential conflicts. It's a good practice to include a close option in your plugin's UI to give users control over its lifecycle.
showUI
The showUI function is used to display your plugin's user interface. This function takes parameters that define the size and appearance of the UI. It's essential for making your plugin interactive and accessible to users. By using showUI, you can control when and how the UI is displayed, ensuring that it integrates seamlessly with the Figma environment. A well-timed and well-designed UI can greatly enhance the user experience and make your plugin more engaging.
showUIAync
The showUIAync function works the same as showUI, but is an async function.
updateSettingsAsync
The updateSettingsAsync function allows you to update settings asynchronously.
getSettingsAsync
The getSettingsAsync function allows you to retrieve saved settings asynchronously.
saveSettingsAsync
The saveSettingsAsync function allows you to save settings asynchronously.
notify
The notify function displays a notification message to the user. This is useful for providing feedback, alerting users to errors, or informing them about the progress of a task. Notifications appear as small pop-up messages within Figma. Use notifications sparingly to avoid overwhelming the user, but make sure to provide clear and concise information when necessary. A well-placed notification can greatly improve the user experience by keeping them informed and engaged.
clientStorage
The clientStorage API allows you to store and retrieve data locally within the user's Figma environment. This is useful for persisting settings, caching data, or storing user-specific information. Client storage is sandboxed, meaning that each plugin has its own isolated storage area. This ensures that plugins don't interfere with each other's data. Use client storage to enhance the user experience by remembering preferences and providing personalized settings.
importGoogleFontsAsync
The importGoogleFontsAsync function allows you to import Google Fonts into your plugin. This is useful for ensuring that your plugin uses the correct fonts and that the text renders correctly. Google Fonts are a widely used resource, and this function makes it easy to integrate them into your plugin. Importing fonts asynchronously ensures that the process doesn't block the main thread, keeping your plugin responsive.
base64EncodeAsync
The base64EncodeAsync function encodes data into a Base64 string asynchronously.
base64DecodeAsync
The base64DecodeAsync function decodes a Base64 string asynchronously.
currentPage
The currentPage property provides access to the current page in the Figma document. This allows you to manipulate layers, add elements, and perform other actions on the active page. The currentPage object contains methods and properties for interacting with the page, making it a fundamental part of many Figma plugins. Understanding how to use currentPage is essential for building plugins that modify or analyze the content of a Figma document.
root
The root property provides access to the root node of the Figma document. This is the top-level container for all layers and elements in the document. Accessing the root node allows you to traverse the entire document structure and manipulate any element within it. Understanding the document hierarchy and how to navigate it using the root property is crucial for building powerful and flexible Figma plugins.
selection
The selection property provides access to the currently selected nodes in the Figma document. This is incredibly useful for plugins that operate on user-selected elements. You can iterate through the selection array to apply transformations, extract data, or perform other actions on the selected nodes. The selection property is essential for building interactive and context-aware plugins that respond to user input.
viewport
The viewport property provides access to the visible area of the Figma canvas. This allows you to determine the current zoom level, scroll position, and other viewport-related information. You can use the viewport property to build plugins that adapt to the user's view or that perform actions relative to the visible area. Understanding the viewport is crucial for creating plugins that provide a seamless and intuitive user experience.
simulateMouseEvent
The simulateMouseEvent function allows you to simulate mouse events within Figma. This can be useful for testing your plugin or for automating certain tasks. By simulating mouse clicks, drags, and other interactions, you can programmatically control the Figma interface. This function is particularly helpful for creating plugins that perform repetitive actions or that require precise control over mouse movements.
simulateKeyEvent
The simulateKeyEvent function allows you to simulate keyboard events within Figma. This can be useful for testing your plugin or for automating certain tasks. By simulating key presses, releases, and other keyboard interactions, you can programmatically control the Figma interface. This function is particularly helpful for creating plugins that respond to keyboard input or that automate text editing tasks.
loadFontAsync
The loadFontAsync function allows you to load fonts asynchronously. Loading fonts asynchronously ensures that the process doesn't block the main thread, keeping your plugin responsive. This is especially important when loading large or complex fonts. Using loadFontAsync ensures that your plugin provides a smooth and seamless user experience, even when working with custom fonts.
measureTextWidthAsync
The measureTextWidthAsync function allows you to measure the width of text asynchronously. This is useful for calculating the layout of text elements or for ensuring that text fits within a specific area. Measuring text width asynchronously ensures that the process doesn't block the main thread, keeping your plugin responsive. This function is essential for creating plugins that work with text and that require precise control over text layout.
inspect
The inspect function is used for debugging your plugin. It allows you to inspect the properties and methods of objects within the Figma environment. This is invaluable for understanding how Figma works and for troubleshooting issues in your plugin. Use inspect to explore the Figma API and to gain a deeper understanding of the document structure.
encryptCredentialsAsync
The encryptCredentialsAsync function allows you to encrypt sensitive data, such as API keys or passwords. This ensures that the data is protected from unauthorized access. Encryption is essential for building secure plugins that handle sensitive information. Use encryptCredentialsAsync to protect your users' data and to comply with security best practices.
decryptCredentialsAsync
The decryptCredentialsAsync function allows you to decrypt data that has been encrypted using encryptCredentialsAsync. This is necessary for accessing the data and using it within your plugin. Decryption should only be performed when necessary and should be done securely to prevent unauthorized access. Use decryptCredentialsAsync to retrieve encrypted data and to use it within your plugin's logic.
Example manifest.json
Here’s a basic example of a manifest.json file to get you started:
{
  "name": "My Awesome Plugin",
  "id": "1234567890",
  "api": "1.0.0",
  "main": "code.js",
  "ui": "ui.html",
  "menu": [
    {
      "name": "Do Something",
      "command": "doSomething"
    }
  ]
}
Best Practices for manifest.json
- Keep it Clean: Make sure your 
manifest.jsonis well-formatted and easy to read. - Use Comments: Add comments to explain what each property does (though JSON doesn't natively support comments, so you might want to keep them in a separate documentation file).
 - Validate: Use a JSON validator to ensure your file is valid.
 - Stay Updated: Keep your 
apiversion up to date to take advantage of the latest features. 
Conclusion
The manifest.json file is the backbone of your Figma plugin. Understanding its properties and how to configure them is crucial for building successful plugins. So, dive in, experiment, and create something amazing! Now that you've got a solid grasp of the manifest file, you're well on your way to becoming a Figma plugin pro. Happy coding, and may your plugins be ever-so-useful!