Vite
Requirements:
- Vite 2 or later
- React 18 or later
- Tailwind CSS 3.4 or later
- Framer Motion 11 or later
To use NextUI in your Vite project, you need to follow the following steps:
Installation
In your Vite React project, run one of the following command to install NextUI:
npm i @nextui-org/react framer-motion
Hoisted Dependencies Setup
Note: This step is only for those who use pnpm to install. If you install NextUI using other package managers, you may skip this step.
If you are using pnpm, you need to add the following line to your .npmrc
file to hoist our packages to the root node_modules
.
public-hoist-pattern[]=*@nextui-org/*
After modifying the .npmrc
file, you need to run pnpm install
again to ensure that the dependencies are installed correctly.
Tailwind CSS Setup
NextUI is built on top of Tailwind CSS, so you need to install Tailwind CSS first. You can follow the official
installation guide to install Tailwind CSS. Then you need to add
the following code to your tailwind.config.js
file:
Note: If you are using pnpm and monorepo architecture, please make sure you are pointing to the ROOT
node_modules
// tailwind.config.jsconst { nextui } = require("@nextui-org/react");/** @type {import('tailwindcss').Config} */module.exports = { content: [ // ... "./node_modules/@nextui-org/theme/dist/**/*.{js,ts,jsx,tsx}" ], theme: { extend: {}, }, darkMode: "class", plugins: [nextui()]}
content: [// ..."./node_modules/@nextui-org/theme/dist/**/*.{js,ts,jsx,tsx}"],theme: {extend: {},},darkMode: "class",plugins: [nextui()]}
Provider Setup
After installing NextUI, you need to set up the NextUIProvider
at the root
of your application.
Go to the src directory and inside main.jsx
or main.tsx
, wrap NextUIProvider
around App:
// main.tsx or main.jsximport React from 'react'import ReactDOM from 'react-dom/client'import {NextUIProvider} from '@nextui-org/react'import App from './App'import './index.css'ReactDOM.createRoot(document.getElementById('root')).render(<React.StrictMode><NextUIProvider><App /></NextUIProvider></React.StrictMode>,)
Version 2 is only compatible with React 18 or later. If you are using React 17 or earlier, please use version 1 of NextUI.