Skip to content

Commit

Permalink
feat: add react-vant + Rsbuild demo (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Nov 18, 2023
1 parent f5fcf98 commit 358a768
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ npm run dev
│ └── base Building mini-programs using Vant Weapp
├── react-vant # Examples related to React Vant
│ └── rsbuild Building applications using React Vant and Rsbuild
│ └── modern-js Building applications using React Vant, Modern.js, and Rspack
└── vant-cli # Examples related to Vant Cli
Expand Down
1 change: 1 addition & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ npm run dev
│ └── base 使用 Vant Weapp 搭建小程序
├── react-vant # React Vant 相关示例
│ └── rsbuild 使用 React Vant 和 Rsbuild 搭建应用
│ └── modern-js 使用 React Vant、Modern.js、Rspack 搭建应用
└── vant-cli # Vant Cli 相关示例
Expand Down
13 changes: 13 additions & 0 deletions react-vant/rsbuild/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Local
.DS_Store
*.local
*.log*

# Dist
node_modules
dist/

# IDE
.vscode/*
!.vscode/extensions.json
.idea
29 changes: 29 additions & 0 deletions react-vant/rsbuild/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Rsbuild Project

## Setup

Install the dependencies:

```bash
pnpm install
```

## Get Started

Start the dev server:

```bash
pnpm dev
```

Build the app for production:

```bash
pnpm build
```

Preview the production build locally:

```bash
pnpm preview
```
23 changes: 23 additions & 0 deletions react-vant/rsbuild/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "rsbuild-react-ts",
"private": true,
"version": "1.0.0",
"scripts": {
"dev": "rsbuild dev --open",
"build": "rsbuild build",
"preview": "rsbuild preview"
},
"dependencies": {
"@react-vant/icons": "^0.0.10",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-vant": "^3.2.5"
},
"devDependencies": {
"@rsbuild/core": "^0.0.25",
"@rsbuild/plugin-react": "^0.0.25",
"@types/react": "^18",
"@types/react-dom": "^18",
"typescript": "^5.2.2"
}
}
6 changes: 6 additions & 0 deletions react-vant/rsbuild/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

export default defineConfig({
plugins: [pluginReact()],
});
49 changes: 49 additions & 0 deletions react-vant/rsbuild/src/App.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
html,
body {
padding: 0;
margin: 0;
font-size: 16px;
font-family: PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;
background-color: #f8f8f8;
-webkit-font-smoothing: antialiased;
}

p {
margin: 0;
}

* {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
box-sizing: border-box;
}

.user {
&-poster {
width: 100%;
height: 53vw;
display: block;
}

&-group {
margin-bottom: 15px;
}

&-links {
padding: 15px 0;
font-size: 12px;
text-align: center;
background-color: #fff;

.rv-icon {
font-size: 24px;
margin-bottom: 4px;
}

.rv-flexitem {
display: flex;
flex-direction: column;
align-items: center;
}
}
}
54 changes: 54 additions & 0 deletions react-vant/rsbuild/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Flex, CellGroup, Cell } from 'react-vant';
import {
Records,
Tosend,
Logistics,
PendingPayment,
Points,
GoldCoinO,
GiftO,
} from '@react-vant/icons';
import './App.scss';

const App = () => (
<div className="container-box">
<main>
<div>
<img
className="user-poster"
src="https://img.yzcdn.cn/public_files/2017/10/23/8690bb321356070e0b8c4404d087f8fd.png"
/>
<Flex className="user-links">
<Flex.Item span="6">
<PendingPayment />
待付款
</Flex.Item>
<Flex.Item span="6">
<Records />
待接单
</Flex.Item>
<Flex.Item span="6">
<Tosend />
待发货
</Flex.Item>
<Flex.Item span="6">
<Logistics />
已发货
</Flex.Item>
</Flex>

<CellGroup className="user-group">
<Cell icon={<Records />} title="全部订单" isLink />
</CellGroup>

<CellGroup>
<Cell icon={<Points />} title="我的积分" isLink />
<Cell icon={<GoldCoinO />} title="我的优惠券" isLink />
<Cell icon={<GiftO />} title="我收到的礼物" isLink />
</CellGroup>
</div>
</main>
</div>
);

export default App;
1 change: 1 addition & 0 deletions react-vant/rsbuild/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@rsbuild/core/types" />
10 changes: 10 additions & 0 deletions react-vant/rsbuild/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

const root = ReactDOM.createRoot(document.getElementById('root')!);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
14 changes: 14 additions & 0 deletions react-vant/rsbuild/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ES2020",
"lib": ["DOM", "ES2020"],
"module": "ESNext",
"jsx": "react-jsx",
"strict": true,
"skipLibCheck": true,
"isolatedModules": true,
"resolveJsonModule": true,
"moduleResolution": "bundler"
},
"include": ["src"]
}

0 comments on commit 358a768

Please sign in to comment.