Install the CSS tailwind for the React project

Tram Ho

In the same article I learn how to install tailwind css for an existing React project.

Tailwind is a utility-first framework with a bunch of flex, pt-4, text-center and rotate-90 classes that are used directly instead of having to think about CSS naming, built-in custom classes …

This article focuses on installing the tailwind on an already existing React project so I will skip the initial React application initialization and start installing the tailwind as well.

At the root of the project we run the command: yarn add tailwindcss postcss-cli autoprefixer -D

Then use the following command to create a default configuration file: npx tailwind init tailwind.js --full

After running, a tailwind.js file will be created.

Next we create a file postcss.config.js, with the following content:

PostCSS is a preprocessing tool, but it is more flexible and powerful than Sass or Less in that it can assist us in creating plugins and reusing someone else’s plugin. That is, we can use CSS in modular form. With PostCSS, we can easily choose the preprocessor we want to use in the project.

Next, create a file taillwind.css at ./src/assets, with the following content:

Then change the package.json file as follows:

A file main.css in the src / assets directory will be generated every time we start the app. Now all we have to do is import that CSS file into App.js.

Thank you for taking the time to find out.

Source: https://dev.to/raphaelmansuy/how-to-add-taillwindcss-to-an-existing-react-project-gap

Share the news now

Source : Viblo