Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Sirima Insorn
Sirima Insorn

Posted on

     

Setting up TailwindCSS in React App project.

Getting Started

First, create a React project with create-react-app:

npx create-react-app react-tailwindcss
Enter fullscreen modeExit fullscreen mode

if Create React App version < 5.0:

npx create-react-app@latest react-tailwindcss
Enter fullscreen modeExit fullscreen mode

or

npx create-react-app@5.0.0 react-tailwindcss
Enter fullscreen modeExit fullscreen mode

Install TailwindCSS

Install the dependencies required for Tailwind CSS:

npm install -D tailwindcss postcss autoprefixer
Enter fullscreen modeExit fullscreen mode

Next, generate your configtailwind.config.js file for your project using the Tailwind CLI utility included when you install thetailwindcss npm package:

npx tailwindcss init
Enter fullscreen modeExit fullscreen mode

It will have the following content:

module.exports = {  content: [],  theme: {    extend: {},  },  plugins: [],}
Enter fullscreen modeExit fullscreen mode

Use the -p flag if you’d like to also generate a basic postcss.config.js file alongside your tailwind.config.js file:

npx tailwindcss init -p
Enter fullscreen modeExit fullscreen mode

This will generate apostcss.config.js file in your project that looks like this:

module.exports = {  plugins: {    tailwindcss: {},    autoprefixer: {},  },}
Enter fullscreen modeExit fullscreen mode

First, we’ll change thecontent key intailwind.config.js:

content: ["./src/**/*.{js,jsx,ts,tsx}"],
Enter fullscreen modeExit fullscreen mode

Include Tailwind in your CSS

Use the@tailwind directive to include Tailwind’s base, components, and utilities styles, replacing the original file contents:

@tailwind base;@tailwind components;@tailwind utilities
Enter fullscreen modeExit fullscreen mode

Let’s start the server now. Run the following command:

npm start
Enter fullscreen modeExit fullscreen mode

Image description

You can view a demo of the website we’re creatinghere

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

devtist
  • Location
    Bangkok, Thailand
  • Joined

More fromSirima Insorn

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp