Creating a new React project with Tailwind CSS on a Linux machine is straightforward. Here’s a step-by-step guide:
First, make sure you have Node.js and npm installed. You can check by running:
node -v
npm -vIf they’re not installed, install Node.js via your package manager or use NodeSource:
# Example for Ubuntu/Debian:
sudo apt update
sudo apt install nodejs npmOr better, install Node.js from NodeSource to get the latest version:
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejsRun:
npx create-react-app my-tailwind-appReplace my-tailwind-app with your preferred project folder name.
cd my-tailwind-appnpm install -D tailwindcss postcss autoprefixerThen initialize Tailwind CSS configuration:
npx tailwindcss init -pThis creates two config files:
tailwind.config.jspostcss.config.js
Edit tailwind.config.js:
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}This tells Tailwind to scan all your React files for class names.
Open src/index.css and replace its contents with:
@tailwind base;
@tailwind components;
@tailwind utilities;npm startOpen http://localhost:3000 in your browser, and Tailwind CSS will be working with your React app.
npx create-react-app my-tailwind-app
cd my-tailwind-app
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
# edit tailwind.config.js to add content path
# replace src/index.css with Tailwind directives
npm start