logoAnt Design

⌘ K
  • 디자인
  • 개발
  • 컴포넌트
  • 블로그
  • 자료
5.21.3
  • React의 Ant Design
  • Ant Design of React
  • Ant Design of React
  • Changelog
    v5.21.3
  • 기본 사용법
    • 시작하기
    • Next.js에서 사용하기
      Updated
  • 如何使用
    • 在 create-react-app 中使用
    • 在 Vite 中使用
    • 在 Next.js 中使用
      Updated
    • 在 Umi 中使用
    • 在 Rsbuild 中使用
      New
    • 在 Farm 中使用
      New
    • 使用 Refine
      New
  • 迁移
    • 从 Less 变量到 Design Token
  • Basic Usage
    • Usage with create-react-app
    • Usage with Vite
    • Usage with Next.js
      Updated
    • Usage with Umi
    • Usage with Rsbuild
      New
    • Usage with Farm
      New
    • Usage with Refine
      New
  • 고급기능
    • 테마 커스터마이징
    • CSS 호환성
    • 서버 사이드 렌더링
    • 커스텀 날짜 라이브러리 사용하기
  • 进阶使用
    • 定制主题
    • 使用 CSS 变量
      New
  • Advanced
    • Customize Theme
    • CSS Variables
      New
    • Internationalization
    • Common Props
  • Migration
    • V4 to V5
    • Less variables to Component Token
  • 其他
    • 社区精选组件
    • 贡献指南
    • FAQ
  • Other
    • Third-Party Libraries
    • Contributing
    • FAQ

在 Farm 中使用

Resources

Ant Design Charts
Ant Design Pro
Ant Design Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Landing-Landing Templates
Scaffolds-Scaffold Market
Umi-React Application Framework
dumi-Component doc generator
qiankun-Micro-Frontends Framework
ahooks-React Hooks Library
Ant Motion-Motion Solution
China Mirror 🇨🇳

Community

Awesome Ant Design
Medium
Twitter
yuque logoAnt Design in YuQue
Ant Design in Zhihu
Experience Cloud Blog
seeconf logoSEE Conf-Experience Tech Conference
Work with Us

Help

GitHub
Change Log
FAQ
Bug Report
Issues
Discussions
StackOverflow
SegmentFault

Ant XTech logoMore Products

yuque logoYuQue-Document Collaboration Platform
AntV logoAntV-Data Visualization
Egg logoEgg-Enterprise Node.js Framework
Kitchen logoKitchen-Sketch Toolkit
Galacean logoGalacean-Interactive Graphics Solution
xtech logoAnt Financial Experience Tech
Theme Editor
Made with ❤ by
Ant Group and Ant Design Community
loading

Farm 是一个基于 Rust 实现的极速构建引擎,帮助您更快地构建 Web 程序 和 JavaScript 库,本文会尝试使用 Farm 创建一个项目,并引入 antd。

安装和初始化

在开始之前,你可能需要安装 yarn 或者 pnpm 或者 bun。

npm iconnpm
yarn iconyarn
pnpm iconpnpm
Bun LogoBun
$ npm create farm@latest

在初始化的过程中,farm 提供了一系列模板供我们选择,这里我们选择 React 模板。

工具会自动初始化一个脚手架并安装 React 项目的各种必要依赖,如果在过程中出现网络问题,请尝试配置代理或使用其他 npm registry。

然后我们进入项目并启动。

$ cd farm-project
$ npm install
$ npm start

此时访问浏览器 http://localhost:9000, 看到 Farm with React 的界面就算成功了。

引入 antd

现在从 yarn 或 npm 或 pnpm 或 bun 安装并引入 antd。

npm iconnpm
yarn iconyarn
pnpm iconpnpm
Bun LogoBun
$ npm install antd --save

修改 src/main.tsx,引入 antd 的 Button 组件。

import React from 'react';
import { Button } from 'antd';
export function Main() {
return (
<div>
<Button type="primary">Button</Button>
</div>
);
}

好了,现在你应该能看到页面上已经有了 antd 的蓝色按钮组件,接下来就可以继续选用其他组件开发应用了。其它开发流程你可以参考 Farm 的官方文档。

自定义主题

参考 配置主题,通过 ConfigProvider 进行主题配置:

import React from 'react';
import { Button, ConfigProvider } from 'antd';
export function Main() {
return (
<ConfigProvider theme={{ token: { colorPrimary: '#00b96b' } }}>
<Button type="primary">Button</Button>
</ConfigProvider>
);
}

我们现在已经把 antd 组件成功使用 Farm 运行起来了,开始开发你的应用吧!