- Install Next.js globally:
npm install -g create-next-app
- Create a new Next.js project with the name "your-project-name":
npx create-next-app your-project-name
- Change into the project directory:
cd your-project-name
- Install the required dependencies for Tailwind CSS:
npm install tailwindcss postcss autoprefixer
- Create a
postcss.config.js
file in the project root:
touch postcss.config.js
- Open
postcss.config.js
and add the following content:
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
- Create a
styles
directory in the src
folder:
mkdir src/styles
- Inside the
styles
directory, create a tailwind.css
file:
touch src/styles/tailwind.css
- Open
src/styles/tailwind.css
and add the following content:
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
- Update the
styles
section in src/globals.css
to import the tailwind.css
file:
@import './styles/tailwind.css';
- Create a Tailwind CSS configuration file:
npx tailwindcss init -p
- Open
tailwind.config.js
and update the purge
section:
module.exports = {
// other configurations...
purge: [
'./src//*.{js,ts,jsx,tsx}',
'./public/index.html',
],
}
- 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"
}
- Run the development server:
npm run dev