Skip to content

Commit eb392e6

Browse files
authored
docs: add guide to install Panda with Rsbuild (#3344)
docs: add guide to install Panda in Rsbuild
1 parent 3f030a2 commit eb392e6

File tree

4 files changed

+636
-0
lines changed

4 files changed

+636
-0
lines changed

website/pages/docs/installation/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"gatsby": "Gatsby",
1010
"ember": "Ember",
1111
"redwood": "Redwood",
12+
"rsbuild": "Rsbuild",
1213
"qwik": "Qwik",
1314
"vite": "Vite",
1415
"vue": "Vue",
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
---
2+
title: Using Rsbuild
3+
description: Easily use Panda with Rsbuild, React and Typescript with our dedicated integration.
4+
---
5+
6+
# Using Panda CSS with Rsbuild
7+
8+
Setting up Panda CSS in a Rsbuild project using PostCSS.
9+
10+
## Start a new project
11+
12+
<Steps>
13+
14+
### Create Rsbuild project
15+
16+
To get started, we will need to create a new Rsbuild project using `react-ts` template.
17+
18+
<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}>
19+
<Tab>
20+
```bash
21+
pnpm create rsbuild@latest --dir test-app --template react-ts
22+
cd test-app
23+
pnpm install
24+
```
25+
</Tab>
26+
<Tab>
27+
```bash
28+
npm create rsbuild@latest --dir test-app -- --template react-ts
29+
cd test-app
30+
npm install
31+
```
32+
</Tab>
33+
<Tab>
34+
```bash
35+
yarn create rsbuild@latest --dir test-app --template react-ts
36+
cd test-app
37+
yarn
38+
```
39+
</Tab>
40+
<Tab>
41+
```bash
42+
bun create rsbuild@latest --dir test-app --template react-ts
43+
cd test-app
44+
bun install
45+
```
46+
</Tab>
47+
</Tabs>
48+
49+
50+
### Install Panda
51+
52+
Install panda and create your `panda.config.ts` file.
53+
54+
<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}>
55+
<Tab>
56+
```bash
57+
pnpm install -D @pandacss/dev
58+
pnpm panda init --postcss
59+
```
60+
</Tab>
61+
<Tab>
62+
```bash
63+
npm install -D @pandacss/dev
64+
npx panda init --postcss
65+
```
66+
</Tab>
67+
<Tab>
68+
```bash
69+
yarn add -D @pandacss/dev
70+
yarn panda init --postcss
71+
```
72+
</Tab>
73+
<Tab>
74+
```bash
75+
bun add -D @pandacss/dev
76+
bun panda init --postcss
77+
```
78+
</Tab>
79+
</Tabs>
80+
81+
### Update package.json scripts
82+
83+
Open your `package.json` file and update the `scripts` section as follows:
84+
85+
```diff {3} filename="package.json"
86+
{
87+
"scripts": {
88+
"build": "rsbuild build",
89+
"dev": "rsbuild dev --open",
90+
+ "prepare": "panda codegen",
91+
"preview": "rsbuild preview"
92+
}
93+
}
94+
```
95+
- `"prepare"` - script that will run Panda CSS CLI codegen before each build. Read more about [codegen](/docs/references/cli#panda-codegen) in the CLI section.
96+
97+
> This step ensures that the panda output directory is regenerated after each dependency installation. So you can add the output directory to your `.gitignore` file and not worry about it.
98+
99+
### Configure the content
100+
101+
Make sure that all of the paths of your React components are included in the `include` section of the `panda.config.ts` file.
102+
103+
```js {8} filename="panda.config.ts"
104+
import { defineConfig } from "@pandacss/dev"
105+
106+
export default defineConfig({
107+
// Whether to use css reset
108+
preflight: true,
109+
110+
// Where to look for your css declarations
111+
include: ["./src/**/*.{js,jsx,ts,tsx}", "./pages/**/*.{js,jsx,ts,tsx}"],
112+
113+
// Files to exclude
114+
exclude: [],
115+
116+
// Generates JSX utilities with options of React, Preact, Qwik, Solid, Vue
117+
jsxFramework: 'react',
118+
119+
// The output directory for your css system
120+
outdir: "styled-system",
121+
})
122+
```
123+
124+
### Configure the entry CSS with layers
125+
126+
Add this code to an `src/App.css` file imported in the root component of your project.
127+
128+
```css filename="src/App.css"
129+
@layer reset, base, tokens, recipes, utilities;
130+
```
131+
132+
## Start your build process
133+
134+
Run the following command to start your development server.
135+
136+
<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}>
137+
<Tab>
138+
```bash
139+
pnpm dev
140+
```
141+
</Tab>
142+
<Tab>
143+
```bash
144+
npm run dev
145+
```
146+
</Tab>
147+
<Tab>
148+
```bash
149+
yarn dev
150+
```
151+
</Tab>
152+
<Tab>
153+
```bash
154+
bun dev
155+
```
156+
</Tab>
157+
</Tabs>
158+
159+
### Start using Panda
160+
161+
Now you can start using Panda CSS in your project.
162+
Here is the snippet of code that you can use in your `src/App.tsx` file.
163+
164+
```tsx filename="src/App.tsx"
165+
import { css } from '../styled-system/css';
166+
167+
function App() {
168+
return (
169+
<div className={css({ fontSize: "2xl", fontWeight: 'bold' })}>Hello 🐼!</div>
170+
)
171+
}
172+
173+
export default App;
174+
```
175+
</Steps>
176+
177+
## Troubleshooting
178+
179+
If you're not getting import autocomplete in your IDE, you may need to include the `styled-system` directory in your `tsconfig.json` file:
180+
181+
```json filename="tsconfig.json"
182+
{
183+
// ...
184+
"include": ["src", "styled-system"]
185+
}
186+
```

0 commit comments

Comments
 (0)