nextjs create project with tailwind

  1. Install Next.js globally:
npm install -g create-next-app
  1. Create a new Next.js project with the name "your-project-name":
npx create-next-app your-project-name
  1. Change into the project directory:
cd your-project-name
  1. Install the required dependencies for Tailwind CSS:
npm install tailwindcss postcss autoprefixer
  1. Create a postcss.config.js file in the project root:
touch postcss.config.js
  1. Open postcss.config.js and add the following content:
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}
  1. Create a styles directory in the src folder:
mkdir src/styles
  1. Inside the styles directory, create a tailwind.css file:
touch src/styles/tailwind.css
  1. Open src/styles/tailwind.css and add the following content:
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
  1. Update the styles section in src/globals.css to import the tailwind.css file:
@import './styles/tailwind.css';
  1. Create a Tailwind CSS configuration file:
npx tailwindcss init -p
  1. Open tailwind.config.js and update the purge section:
module.exports = {
  // other configurations...

  purge: [
    './src//*.{js,ts,jsx,tsx}',
    './public/index.html',
  ],
}
  1. Add a script to your package.json to run the development server with Tailwind CSS:
"scripts": {
  "dev": "next dev",
  "build": "next build",
  "start": "next start",
  "css:watch": "postcss src/styles/tailwind.css -o src/styles/global.css",
  "css:build": "postcss src/styles/tailwind.css -o src/styles/global.css"
}
  1. Run the development server:
npm run dev