0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-09 00:10:12 -05:00
penpot-plugins/docs/create-plugin.md

79 lines
2.3 KiB
Markdown
Raw Normal View History

2024-03-27 07:57:02 -05:00
# Creating a Plugin
2024-03-12 01:48:02 -05:00
2024-03-27 07:57:02 -05:00
This guide walks you through the steps to create a plugin for our platform. You'll start by setting up the basic structure, configuring necessary files, and then running a local server to preview your plugin. Let's dive in.
2024-03-12 01:48:02 -05:00
2024-03-27 07:57:02 -05:00
### Step 1: Initialize the Plugin
First, you need to create the scaffolding for your plugin. Use the following command, replacing `example-plugin` with the name of your plugin:
```sh
2024-02-06 06:16:28 -05:00
npx nx g @nx/web:application example-plugin --directory=apps/example-plugin
2024-03-12 01:48:02 -05:00
```
2024-02-06 06:16:28 -05:00
2024-03-27 07:57:02 -05:00
### Step 2: Configure the Manifest
Next, create a `manifest.json` file inside the `/public` directory. This file is crucial as it defines key properties of your plugin, including permissions and the entry point script.
2024-02-06 06:16:28 -05:00
```json
{
2024-03-27 07:57:02 -05:00
"name": "Example Plugin",
2024-03-04 04:49:53 -05:00
"code": "http://localhost:4201/plugin.js",
"permissions": ["page:read", "file:read", "selection:read"]
2024-02-06 06:16:28 -05:00
}
```
2024-03-27 07:57:02 -05:00
### Step 3: Update Vite Configuration
2024-02-06 06:16:28 -05:00
2024-03-27 07:57:02 -05:00
Now, add the following configuration to your `vite.config.ts` to specify the entry points for the build process:
```typescript
2024-02-06 06:16:28 -05:00
build: {
rollupOptions: {
input: {
plugin: 'src/plugin.ts',
index: './index.html',
},
output: {
entryFileNames: '[name].js',
},
},
}
```
2024-03-27 07:57:02 -05:00
### Step 4: Modify TypeScript Configuration
Update your `tsconfig.app.json` to include the necessary TypeScript files for your plugin:
2024-02-27 08:50:38 -05:00
```json
2024-03-27 07:57:02 -05:00
{
"include": ["src/**/*.ts", "../../libs/plugin-types/index.d.ts"]
}
2024-02-27 08:50:38 -05:00
```
2024-03-27 07:57:02 -05:00
### Step 5: Run a Static Server
2024-02-06 06:16:28 -05:00
2024-03-27 07:57:02 -05:00
To preview your plugin, start a static server by running:
```sh
npx nx run example-plugin:build --watch & npx nx run example-plugin:preview
2024-03-12 01:48:02 -05:00
```
2024-03-27 07:57:02 -05:00
### Step 6: Load the Plugin in Penpot
Finally, to load your plugin into Penpot, execute the following command in the browser's console devtools:
2024-02-06 06:16:28 -05:00
2024-03-27 07:57:02 -05:00
```typescript
2024-05-22 01:21:06 -05:00
ɵloadPluginByUrl('http://localhost:4201/manifest.json');
2024-02-06 06:16:28 -05:00
```
2024-03-12 01:48:02 -05:00
2024-03-27 07:57:02 -05:00
### Learn More About Plugin Development
For more detailed information on plugin development, check out our guides:
- [Plugin Usage Documentation](docs/plugin-usage.md)
- [Create API Documentation](docs/create-api.md)
### Using a Starter Template
2024-03-12 01:48:02 -05:00
2024-03-27 07:57:02 -05:00
If you prefer to kickstart your plugin development, consider using the [Penpot Plugin Starter Template](https://github.com/penpot/penpot-plugin-starter-template). It's a template designed to streamline the creation process for Penpot plugins.