The main focus of this repository is just to get the css file for our html in one bundle - CSS/output.css
-
Install node or npm globally.
-
Initialize the package.json file
npm init -y
- Install tailwind as a dev dependency and will create node modules folder which has all the dependencies and you can see that in your packagae.json in dev dependencies.
npm install -D tailwindcss
- Create the tailwind.config.js file
npx tailwindcss init
- We have to tell tailwind where to look for utility classes so we will change the content as content: ["*", "./src/backend/homepage.js"]. * means all and we have to specify to use tailwind css classes in our javascript files as well. We can specify certain folder only also according to our need. Eg:
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["*", "./src/backend/homepage.js"],
theme: {
extend: {},
},
plugins: [],
}
- Create a input.css file in the source folder or root. This will be responsible just for the development and we have to generate the final file from this input file. Add these below lines in input.css. These are the layers of tailwind. The CLI will compile this file and it will also compile your custom css.
@tailwind base;
@tailwind components;
@tailwind utilities;
- Go to package.json and add the path to input.css wherever that is, can be in your root or src, give the whole relative path and it will generate a final css. npx tailwindcss -i ./src/frontend/CSS/input.css - This line will take input.css and compile the tailwindcss layers and all the utility classes and aslo all your custom css into the output.css which is denoted by - ./src/frontend/CSS/input.css -o ./CSS/output.css.
"scripts": {
"build": "npx tailwindcss -i ./src/frontend/CSS/input.css -o ./CSS/output.css",
"watch": "npx tailwindcss -i ./src/frontend/CSS/input.css -o ./CSS/output.css --watch"
},
OR
{
"name": "tailwind-hosting",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "npx tailwindcss -i ./src/frontend/CSS/input.css -o ./CSS/output.css",
"watch": "npx tailwindcss -i ./src/frontend/CSS/input.css -o ./CSS/output.css --watch"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"tailwindcss": "^3.1.8"
}
}
- Create an index.html in root only. Include the output.css, i.e. /CSS/output.css
<link rel="stylesheet" href="/CSS/output.css">
- Do the npm build
npm run build
- To start working on your project do the npm run watch
npm run watch
- Start the live server and you are good to go. Remember, /CSS/output.css is your main file which you have to include for hosting.