ant-design/docs/react/use-with-vite.en-US.md
lijianan 81c26096be
docs: update site use-with-vite (#42906)
* docs: update use-with-vite

* update

* fix
2023-06-12 15:44:44 +08:00

1.9 KiB

order title
4 Usage with vite

vite is one of the best React application development tools. We are going to use antd within it and modify the vite config for some customized needs.

Install and Initialization

Before all start, you may need install yarn or pnpm.

The tool will create and initialize environment and dependencies automatically, please try config your proxy setting, or use another npm registry if any network errors happen during it.

Then we go inside antd-demo install dependencies and start it.

$ cd antd-demo
$ npm install
$ npm run dev

Open the browser at http://localhost:5173/. It renders a header saying Vite + React on the page.

Import antd

Below is the default directory structure.

├── public
│   └── vite.svg
├── src
│   └── assets
│       └── react.svg
│   ├── App.css
│   ├── App.js
│   ├── index.css
│   ├── main.js
│   └── logo.svg
├── index.html
├── package.json
└── vite.config.ts

Now we install antd from yarn or npm.

$ npm install antd --save

Modify src/App.js, import Button component from antd.

import React from 'react';
import { Button } from 'antd';

const App = () => (
  <div className="App">
    <Button type="primary">Button</Button>
  </div>
);

export default App;

OK, you should now see a blue primary button displayed on the page. Next you can choose any components of antd to develop your application. Visit other workflows of vite at its User Guide.

We are successfully running antd components now, go build your own application!