首页
/ Create Figma Plugin 项目教程

Create Figma Plugin 项目教程

2026-01-20 02:15:18作者:戚魁泉Nursing

1. 项目的目录结构及介绍

create-figma-plugin/
├── .github/
│   └── workflows/
├── .vscode/
│   └── settings.json
├── docs/
│   ├── changelog.md
│   ├── quick-start.md
│   └── ...
├── src/
│   ├── commands/
│   │   ├── command1.ts
│   │   └── command2.ts
│   ├── components/
│   │   ├── component1.tsx
│   │   └── component2.tsx
│   ├── main.ts
│   ├── ui.tsx
│   └── ...
├── .gitignore
├── package.json
├── tsconfig.json
└── ...

目录结构介绍

  • .github/: 包含GitHub Actions的工作流配置文件。
  • .vscode/: 包含VSCode的设置文件。
  • docs/: 包含项目的文档文件,如变更日志、快速开始指南等。
  • src/: 项目的源代码目录,包含命令、组件、主入口文件等。
    • commands/: 包含插件的命令文件。
    • components/: 包含插件的UI组件文件。
    • main.ts: 插件的主入口文件。
    • ui.tsx: 插件的UI入口文件。
  • .gitignore: Git忽略文件配置。
  • package.json: 项目的依赖和脚本配置文件。
  • tsconfig.json: TypeScript配置文件。

2. 项目的启动文件介绍

main.ts

main.ts 是插件的主入口文件,负责初始化插件并处理插件的主要逻辑。通常,它会注册插件的命令并处理与Figma的交互。

import { loadFontsAsync, showUI } from '@create-figma-plugin/utilities';

export default async function () {
  await loadFontsAsync();
  showUI({ width: 240, height: 120 });
}

ui.tsx

ui.tsx 是插件的UI入口文件,负责渲染插件的用户界面。通常,它会使用Preact组件来构建UI。

import { render } from 'preact';
import { Button } from '@create-figma-plugin/ui';

export default function () {
  const container = document.createElement('div');
  document.body.appendChild(container);

  render(<Button onClick={() => console.log('Button clicked!')}>Click me</Button>, container);
}

3. 项目的配置文件介绍

package.json

package.json 是项目的依赖和脚本配置文件,包含了项目的元数据、依赖项、脚本等信息。

{
  "name": "create-figma-plugin",
  "version": "1.0.0",
  "main": "src/main.ts",
  "scripts": {
    "build": "build-figma-plugin",
    "watch": "build-figma-plugin --watch"
  },
  "dependencies": {
    "@create-figma-plugin/utilities": "^1.0.0",
    "preact": "^10.5.13"
  },
  "devDependencies": {
    "@create-figma-plugin/build": "^1.0.0"
  }
}

tsconfig.json

tsconfig.json 是TypeScript的配置文件,定义了TypeScript编译器的选项。

{
  "compilerOptions": {
    "target": "es6",
    "module": "esnext",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "jsx": "react",
    "jsxFactory": "h",
    "jsxFragmentFactory": "Fragment"
  },
  "include": ["src/**/*"]
}

通过以上配置,您可以快速了解并开始使用 create-figma-plugin 项目。

登录后查看全文
热门项目推荐
相关项目推荐

项目优选

收起
docsdocs
暂无描述
Markdown
827
5.48 K
kernelkernel
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
494
515
ops-nnops-nn
本项目是CANN提供的神经网络类计算算子库,实现网络在NPU上加速计算。
C++
783
1.57 K
pytorchpytorch
作为 Ascend for PyTorch 社区的核心组件,TorchNPU 是昇腾专为 PyTorch 打造的深度学习适配插件,使 PyTorch 框架能够直接调用昇腾 NPU,为开发者提供昇腾 AI 处理器的超强算力。
Python
800
1.14 K
ops-transformerops-transformer
本项目是CANN提供的transformer类大模型算子库,实现网络在NPU上加速计算。
C++
970
2.28 K
kernelkernel
deepin linux kernel
C
32
16
AscendNPU-IRAscendNPU-IR
AscendNPU-IR是基于MLIR(Multi-Level Intermediate Representation)构建的,面向昇腾亲和算子编译时使用的中间表示,提供昇腾完备表达能力,通过编译优化提升昇腾AI处理器计算效率,支持通过生态框架使能昇腾AI处理器与深度调优
C++
480
312
jiuwenswarmjiuwenswarm
JiuwenSwarm 是一款基于openJiuwen开发的智能AI Agent,它能够将大语言模型的强大能力,通过你日常使用的各类通讯应用,直接延伸至你的指尖。
Python
3.01 K
766
cannbot-skillscannbot-skills
CANNBot 是面向 CANN 开发的用于提升开发效率的系列智能体,本仓库为其提供可复用的 Skills 模块。
Markdown
1.26 K
808
cann-learning-hubcann-learning-hub
CANN 学习中心仓,支持在线互动运行、边学边练,提供教程、示例与优化方案,一站式助力昇腾开发者快速上手。
Jupyter Notebook
647
284