This template provides a stater setup to get React working in Vite with TailwindCSS installed.
git clone https://github.com/purnasth/vite-react-tailwind-starter.git
git checkout vrt
git checkout vrt-ts
Run the following commands in your terminal:
npm install
npm run dev
npm install
to install the node_modules on your local repo which has been .gitignore in this github repo.npm run dev
for running this in your browser, by default it opens in port http://localhost:5173/
git clone https://github.com/purnasth/vite-react-tailwind-starter.git
the main branch
Run the following commands in your terminal:
pnpm install
pnpm dev
pnpm install
to install the node_modules on your local repo which has been .gitignore in this github repo.pnpm dev
for running this in your browser, by default it opens in port http://localhost:5173/
NOTE:
Please disregard these below provided codes if you've already completed the first two steps of the "Getting Started" section. It's only meant for those interested in manually creating a project from scratch with Vite + React, Typescript, TailwindCSS and Prettier (Auto Formatting) with pnpm.
pnpm create vite@latest ./ --template react
# y to proceed
# Select a framework: react
# Select a variant: TypeScript + SWC
pnpm install
pnpm run dev
npm run dev -- --host
pnpm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
theme: {
extend: {
colors: {
dark: "#111111",
},
fontSize: {
inherit: "inherit",
},
screens: {
sm: "640px",
md: "768px",
lg: "1024px",
xl: "1280px",
"2xl": "1600px",
"3xl": "1920px",
},
container: {
center: true,
padding: "1rem",
screens: {
sm: "100%",
md: "100%",
lg: "1024px",
xl: "1280px",
"2xl": "1600px",
},
},
},
},
plugins: [],
};
@tailwind base;
@tailwind components;
@tailwind utilities;
If you encounter the error React is not defined
or React is defined but never used
, add the following line to the top of your tsconfig.json
file:
{
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.node.json"
}
],
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
}
}
pnpm install -D prettier
Create a file named .prettierrc
in the root directory and add the following lines:
{
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"useTabs": false,
"printWidth": 80,
"endOfLine": "auto"
}
Add the following lines to the scripts
object in your package.json
file:
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}\"",
"format:check": "prettier --check \"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}\""
pnpm run format
pnpm i -D prettier prettier-plugin-tailwindcss
NOTE:
Enable the formatOnSave
option in your editor to auto-format your code with Prettier. You can also run the pnpm run format
command to format your code.
Cheers! Now on every save, your code will be auto-formatted. Congratulations!
pnpm install react-router-dom
pnpm install react-icons
⭐ Star this repo on GitHub — it helps!