|
| 1 | +--- |
| 2 | +name: React with AntD & Tailwind CSS |
| 3 | +description: Simple example extension using React, Tailwind CSS, and AntD components. |
| 4 | +--- |
| 5 | + |
| 6 | +# WXT + React + AntD + Tailwind CSS |
| 7 | + |
| 8 | +This example demonstrates how to integrate React 19+, Tailwind CSS v4+, and AntD components within a WXT extension. |
| 9 | + |
| 10 | +## Installation Walkthrough |
| 11 | + |
| 12 | +1. **Initialize a new WXT project:** |
| 13 | + |
| 14 | + Open your terminal and run the following command to create a new WXT project with the React template: |
| 15 | + |
| 16 | + ```sh |
| 17 | + pnpm dlx wxt@latest init |
| 18 | + ``` |
| 19 | + |
| 20 | + The CLI will guide you through the project setup. Choose the `react` template and your preferred package manager. For this example, I use pnpm. |
| 21 | + |
| 22 | + ``` |
| 23 | + WXT 0.20.6 |
| 24 | + ℹ Initializing new project |
| 25 | + ✔ Project Directory … react-antd-tailwindcss |
| 26 | + ✔ Choose a template › react |
| 27 | + ✔ Package Manager › pnpm |
| 28 | + ✔ Downloading template |
| 29 | + ✨ WXT project created with the react template. |
| 30 | + Next steps: |
| 31 | + 1. cd react-antd-tailwindcss |
| 32 | + 2. pnpm install |
| 33 | + ``` |
| 34 | + |
| 35 | +2. **Navigate to the project directory and install dependencies:** |
| 36 | + |
| 37 | + ```sh |
| 38 | + cd react-antd-tailwindcss |
| 39 | + pnpm install |
| 40 | + ``` |
| 41 | + |
| 42 | +3. **Install Tailwind CSS and `@tailwindcss/vite`:** |
| 43 | + |
| 44 | + You should follow the official Tailwind Vite installation [guide](https://tailwindcss.com/docs/installation/using-vite). As the time of creating this example, it asked to run the following command: |
| 45 | + |
| 46 | + ```sh |
| 47 | + pnpm install tailwindcss @tailwindcss/vite |
| 48 | + ``` |
| 49 | + |
| 50 | +4. **Configure Tailwind CSS in `wxt.config.ts`:** |
| 51 | + |
| 52 | + To configure Tailwind CSS, modify `wxt.config.ts`. While official documentation says to change `vite.config.ts`, WXT configures Vite internally, so you need to update `wxt.config.ts` instead. This file manages the build process. To integrate Tailwind, add it as a Vite plugin within the wxt.config.ts file, as shown here: |
| 53 | + |
| 54 | + ```ts |
| 55 | + import { defineConfig } from "wxt"; |
| 56 | + import tailwindcss from "@tailwindcss/vite"; |
| 57 | + // See https://wxt.dev/api/config.html |
| 58 | + export default defineConfig({ |
| 59 | + modules: ["@wxt-dev/module-react"], |
| 60 | + vite: () => ({ |
| 61 | + plugins: [tailwindcss()], |
| 62 | + }), |
| 63 | + }); |
| 64 | + ``` |
| 65 | + |
| 66 | +5. **Create a `tailwind.css` file:** |
| 67 | + |
| 68 | + Create a `tailwind.css` file in your `assets` directory (or the root directory of your project if you don't have an assets dir) with the following content: |
| 69 | + |
| 70 | + ```css |
| 71 | + @import "tailwindcss"; |
| 72 | + ``` |
| 73 | + |
| 74 | +6. **Import `tailwind.css`:** |
| 75 | + |
| 76 | + You can now easily import the `tailwind.css` file in your React components: |
| 77 | + |
| 78 | + ```ts |
| 79 | + import "@/assets/tailwind.css"; // Adjust the path if necessary |
| 80 | + ``` |
| 81 | + |
| 82 | + or you can include it directly in your `index.html` file: |
| 83 | + |
| 84 | + ```html |
| 85 | + <!doctype html> |
| 86 | + <html> |
| 87 | + <head> |
| 88 | + <meta charset="UTF-8" /> |
| 89 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 90 | + <link href="@/assets/tailwind.css" rel="stylesheet" /> |
| 91 | + </head> |
| 92 | + <body></body> |
| 93 | + </html> |
| 94 | + ``` |
| 95 | + |
| 96 | + Now you can use AntD and TailwindCSS together throughout your project. |
0 commit comments