展示 HN:开源 Figma 设计转代码
Show HN: Open-source Figma design to code

原始链接: https://github.com/vibeflowing-inc/vibe_figma

## VibeFigma:Figma 到 React 组件转换器 VibeFigma 自动将 Figma 设计转换为可用于生产的 React 组件,并使用 Tailwind CSS。它直接集成 Figma API,准确提取设计数据并生成干净、易于维护的代码 – 无需安装! 只需在设置 Figma API token 为环境变量后,运行 `npx vibefigma [figma-url] --token YOUR_FIGMA_TOKEN`。你可以使用诸如指定组件和资源目录、禁用 Tailwind,或启用 AI 驱动的代码优化和清理(需要 Google AI API key)等选项来定制输出。 **主要特性:** * **Figma API 集成:** 准确的设计提取。 * **React/TypeScript 生成:** 将 Figma 画布转换为组件。 * **Tailwind CSS:** 自动生成类 (默认)。 * **定制化:** 控制输出路径,禁用 Tailwind,并优化代码。 * **REST API:** 包含用于转换的 REST API。 详细的使用说明和选项可通过 `npx vibefigma --help` 获取。欢迎贡献!

VibeFlow,一家YC S25创业公司,发布了一款开源工具,可以将Figma设计转换为可用的React + Tailwind代码。该工具旨在加速原型设计,它以Figma框架作为输入,生成可直接使用的前端组件和资源。 用户可以通过GitHub ([https://github.com/vibeflowing-inc](https://github.com/vibeflowing-inc)) 或他们的网页界面 ([https://app.vibeflow.ai/](https://app.vibeflow.ai/)) 尝试VibeFlow,无需任何设置。 有评论员指出,该工具似乎没有利用人工智能,而是自动化了类似于Figma“Dev Mode”的功能——后者不幸需要付费,使得VibeFlow有可能成为访问该功能的替代方案。开发者欢迎大家提问关于其工作原理。
相关文章

原文

Transform your Figma designs into production-ready React components with Tailwind CSS automatically. VibeFigma leverages the official Figma API to accurately extract design information and generate clean, maintainable code.

  • Official Figma API Integration - Direct integration with Figma's API for accurate design extraction
  • React Component Generation - Convert Figma frames to React/TypeScript components
  • Tailwind CSS Support - Automatic Tailwind class generation (enabled by default)
  • Code Optimization - Optional AI-powered code cleanup

Step 1: 🔑 Getting a Figma Access Token

  1. Go to Figma Account Settings
  2. Scroll to Personal Access Tokens
  3. Click Generate new token
  4. Give it a name and click Generate
  5. Copy the token (you won't see it again!)

Set it as an environment variable:

# Linux/Mac
export FIGMA_TOKEN=your_token_here

# Windows (PowerShell)
$env:FIGMA_TOKEN="your_token_here"

# Windows (CMD)
set FIGMA_TOKEN=your_token_here

No installation required! Just run:

npx vibefigma [figma-url] --token YOUR_FIGMA_TOKEN

# Example with a public design:
npx vibefigma "https://www.figma.com/design/rZbJ7EQucq6UCkqlIl1a6P/Personal-Portfolio-Website-Template--Community?node-id=7-191" --token YOUR_TOKEN

Using Environment Variable

Set your Figma token once:

export FIGMA_TOKEN=your_figma_access_token
npx vibefigma "https://www.figma.com/design/YOUR_FILE_ID"
npx vibefigma --interactive

This will prompt you for:

  • Figma URL
  • Access token (if not set in environment)
  • Output paths
# Convert a Figma design to React component
npx vibefigma "https://www.figma.com/design/YOUR_FILE_ID?node-id=X-Y"
# Save to specific directory
npx vibefigma [url] -c ./src/components -a ./public/assets

# Save to specific file
npx vibefigma [url] -c ./src/components/Hero.tsx
# Generate regular CSS instead of Tailwind
npx vibefigma [url] --no-tailwind
npx vibefigma [url] \
  --token YOUR_TOKEN \
  --component ./src/components \
  --assets ./public/assets \
  --optimize \
  --clean
Usage: vibefigma [options] [url]

Convert Figma designs to React components

Arguments:
  url                           Figma file/node URL

Options:
  -V, --version                 Output the version number
  -t, --token <token>           Figma access token (overrides FIGMA_TOKEN env var)
  -u, --url <url>               Figma file/node URL
  -c, --component <path>        Component output path (default: ./src/components/[ComponentName].tsx)
  -a, --assets <dir>            Assets directory (default: ./public)
  --no-tailwind                 Disable Tailwind CSS (enabled by default)
  --optimize                    Optimize components
  --clean                       Use AI code cleaner (requires GOOGLE_GENERATIVE_AI_API_KEY)
  --no-classes                  Don't generate CSS classes
  --no-absolute                 Don't use absolute positioning
  --no-responsive               Disable responsive design
  --no-fonts                    Don't include fonts
  --interactive                 Force interactive mode
  -h, --help                    Display help for command

This project also includes a REST API server:

# Install dependencies
bun install

# Run development server
bun run dev

# Server runs on http://localhost:3000

Create a .env file:

GOOGLE_GENERATIVE_AI_API_KEY=your_google_ai_key
PORT=3000
HOST=0.0.0.0
CORS_ORIGIN=*

The project includes a REST API for Figma to React conversion:

See API.md for full API documentation.

# Run CLI in development mode
bun run dev:cli

# Build CLI
bun run build:cli

# Test CLI locally
bun run cli -- --help

Contributions are welcome! Please feel free to submit a Pull Request.

This project includes code derived from css-to-tailwindcss by Salakhutdinov Salavat, licensed under the MIT License.

This project is licensed under the Functional Source License, Version 1.1, MIT Future License (FSL-1.1-MIT). See the LICENSE file for the full license text.

See the NOTICE file for details about third-party code used in this project.

联系我们 contact @ memedata.com