Create Figma Plugin 项目教程

Create Figma Plugin 项目教程

项目地址:https://gitcode.com/gh_mirrors/cr/create-figma-plugin

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 项目。

create-figma-plugin :battery: The comprehensive toolkit for developing plugins and widgets for Figma and FigJam create-figma-plugin 项目地址: https://gitcode.com/gh_mirrors/cr/create-figma-plugin

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

余钧冰Daniel

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值