1. Configuring Tailwind CSS without using PostCSS plugin
Make a folder with any name and open the folder path in the terminal (You can use VS Code built-in terminal).
- Create package.json file ๐ฆ
npm init -y //default options
- Install tailwind CSS using npm
npm i tailwindcss
- Install Autoprefixer
npm i autoprefixer //For different browsers support
- Create a folder ๐ name public, inside public folder create a file ๐ named index.html and create another folder ๐ named src , inside src folder create a file ๐ named tailwind.css.
Your file structure should look like this
โโโ tailwindcss
โ โโโ public
โ โ โโโ index.html
โ โโโ src
โ โ โโโ tailwind.css
.
.
.
- Open src/tailwind.css ๐ and copy-paste below code ๐
@tailwind base;
@tailwind components;
/* Write Custom CSS */
@tailwind utilities;
- Create a build scrip which compiles the src/tailwind.css ๐ and make actual compiled css inside the public folder ๐, open package.json ๐ฆ file and copy-paste below code.
"scripts": {"build": "tailwindcss build ./src/tailwind.css -o ./public/tailwind.css"}
- Run build script
npm run build
This will generate compiled css inside the public folder ๐, and link this css in your index.html ๐(Note: Don't modify compiled css)
Customize tailwind CSS Config
- First create tailwind config file with the following command
npx tailwindcss init
It will generate tailwind.config.js ๐
In talwind.config.js ๐ you can define your own custom property.
after changing talwind.config.js ๐ again you need to run build script
npm run build
Compress size of tailwind.css(Production ready)
- Install NODE_ENV
npm install win-node-env
- In package.json ๐ฆ file add the following script which reduces the compiled CSS (It will remove unused classes)
"prod": "NODE_ENV=production npx tailwindcss build ./src/tailwind.css -o ./public/tailwind.cssโ
- Open tailwind.config.js ๐ file add the following line in PURG.
purge:['./public/**/*.html']
- Now you can make production ready ๐ช CSS by running the following command
npm run prod
2. Configuring Tailwind CSS with as PostCSS plugin
- Create package.json ๐ฆ file
npm init -y //default options
- Install tailwind CSS using npm
npm i tailwindcss
- Install Autoprefixer
npm i autoprefixer //For different browsers support
- Install PostCSS-CLI Plugin
npm i postcss-cli
- Create Configuration files for Tailwind CSS and PostCSS using following command
npx tailwindcss init -p
This will generate two files tailwind.config.js and postcss.config.js
- Create a folder name public , inside public folder ๐ create a file named index.html ๐ and create another folder named src , inside src folder ๐ create a file named tailwind.css ๐.
Your file structure should look like this
โโโ tailwindcss
โ โโโ public
โ โ โโโ index.html
โ โโโ src
โ โ โโโ tailwind.css
.
.
.
- Open src/tailwind.css ๐ and copy-paste below code
@tailwind base;
@tailwind components;
/* Write Custom CSS */
@tailwind utilities;
- Create a build scrip which compiles the src/tailwind.css ๐ and make actual compiled css inside the public folder ๐, open package.json ๐ฆ file and copy-paste below code.
"scripts": {"build": "postcss build ./src/tailwind.css -o ./public/tailwind.css"}
- Run build script
npm run build
This will generate compiled css inside the public folder ๐, and link this css in your index.html(Note: Don't modify compiled css)
Customize tailwind CSS Config
- First create tailwind config file with the following command
npx tailwindcss init
It will generate tailwind.config.js ๐
In talwind.config.js ๐ you can define your own custom property.
after changing talwind.config.js ๐again you need to run the build script
npm run build
Compress size of tailwind.css(Production ready)
- Install NODE_ENV
npm install win-node-env
- In package.json ๐ฆ file add the following script which reduces the compiled css (It will remove unused classes)
"prod": "NODE_ENV=production npx tailwindcss build ./src/tailwind.css -o ./public/tailwind.cssโ
- Open tailwind.config.js ๐ file add the following line in purg.
purge:['./public/**/*.html']
- Now you can make production ready ๐ช CSS by running the following command
npm run prod
Top comments (1)
Thanks! I just want to mention that Tailwind v4 is now using
@tailwindcss/cli