nextjs tailwind
- Install Next.js and create a new Next.js app:
npx create-next-app my-nextjs-app
cd my-nextjs-app
- Install and configure Tailwind CSS:
npm install tailwindcss postcss autoprefixer
- Create a configuration file for Tailwind CSS:
npx tailwindcss init -p
- Modify the
tailwind.config.js
file:
module.exports = {
content: [
'./app//*.{js,ts,jsx,tsx}',
'./pages//*.{js,ts,jsx,tsx}',
'./components//*.{js,ts,jsx,tsx}',
],
// other configurations...
}
- Create a PostCSS configuration file (
postcss.config.js
):
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
- Import the Tailwind CSS styles into your project. Create a new CSS file (e.g.,
styles/tailwind.css
) and add the following:
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
- Import the
tailwind.css
file into your global styles. Update thestyles/globals.css
file:
/ other global styles /
@import './tailwind.css';
- Update the
package.json
file to include a build script that processes Tailwind CSS:
"scripts": {
"build": "postcss styles/tailwind.css -o styles/globals.css"
}
- Run the build script to generate the Tailwind CSS styles:
npm run build
- Start your Next.js development server:
npm run dev
Now, your Next.js app is set up with Tailwind CSS. You can use Tailwind classes in your components and styles.