Build Figma plugins using Marko Run
As you probably know, Figma plugin pages need to embed all assets. You cannot make requests from the UI to the plugin's main thread to get additional assets.
Here's what this adapter does:
- Builds your plugin using the static adapter
- Then, for each generated page it:
- Parses the pages's HTML to get all the assets (js, images, and css) using htmlparser2
- Uses esbuild to bundle all the js into a single IIFE
- Inlines all assets into the HTML
- Updates the plugin's
manifest.json
with the path to each page
NOTE: Only
<script>
,<img>
, and<link>
tags will be processed and they will only be inlined if their source is a local file.
npm install @marko-polo/run-adapter-figma
In your application's Vite config file (eg. vite.config.js
), import and register this adapter with the @marko/run
Vite plugin:
import { defineConfig } from "vite";
import marko from "@marko/run/vite";
import figmaAdapter from "@marko/run-adapter-figma";
export default defineConfig({
plugins: [
marko({
adapter: figmaAdapter()
})
]
});
To improve and automate the developer experience, the following tooling has been automatically installed and pre-configured using moonrepo presets.
- Babel for transpiling, configured with babel-preset-moon.
- ESLint for linting, configured with eslint-config-moon.
- Prettier for code formatting, configured with prettier-config-moon.
- Rollup for bundling and distributing, configured dynamically with Packemon.
- TypeScript for type checking, configured with tsconfig-moon.
Feel free to use the configuration as-is, or to modify, or to not use moon, the choice is yours!
The tooling mentioned above can be ran with the following yarn/npm scripts. For example,
yarn run build
.
build
- Build the package(s) with Packemon. Useful for development, as it will only build JavaScript targets. Usepack
for distribution.clean
- Clean all output targets that were built with Packemon.pack
- Clean, build, and validate the package(s) with Packemon. Designed for production and should be ran before a release.release
- Pack the package(s), run test checks, and publish to npm! (Release script not configured by Packemon)validate
- Validate the package(s), ensuring theirpackage.json
is defined correctly.watch
- Watch for file changes and rebuild the target package. Useful for development.
check
- Run the type checker, linter, and testing suite all at once.format
- Run Prettier and format all files in the project.lint
- Run the linter with ESLint.test
,coverage
- Run the unit testing suite with Vitest, and optionally with code coverage.type
- Run the type checker with TypeScript.