using tailwind in react code example
Example 1: create react app and tailwind
1. npx create-react-app .
2. npm i -D tailwindcss postcss-cli autoprefixer
or
npm install tailwindcss@latest postcss@latest autoprefixer@latest
3.npx tailwind init tailwind.js --full
4. touch postcss.config.js
__________________________________________
const tailwindcss = require('tailwindcss');
module.exports = {
plugins: [
tailwindcss('./tailwind.js'),
require('autoprefixer')
]
}
__________________________________________
5. inside scr, create assets folder src/assets
- create tailwind.css and main.css
in tailwind, add this code
___________________________________________
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
___________________________________________
6. Open package.json and add this iside the scripts
___________________________________________
"start": "npm run watch:css && react-scripts start",
"build": "npm run build:css && react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"build:css": "postcss src/assets/tailwind.css -o src/assets/main.css",
"watch:css": "postcss src/assets/tailwind.css -o src/assets/main.css"
____________________________________________
7. run 'npm start'
add this to index.js
_____________________________________
import React from 'react';
import ReactDOM from 'react-dom';
import './assets/main.css';
import App from './App';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
_________________________________
install router
1. npm i --save react-router-dom
Example 2: commmand for installing tailwind to react
npm install tailwindcss
Example 3: how to properly install tailwind css in react
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
Example 4: how to setup tailwind for reactjs
npm install -D tailwindcss@npm:@tailwindcss/postcss7-compat @tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9
Example 5: how to properly install tailwind css in react
const tailwindcss = require('tailwindcss');
module.exports = {
plugins: [
tailwindcss('./tailwind.js'),
require('autoprefixer')
],
};