Giter VIP home page Giter VIP logo

generate-final-css-for-hosting-tailwindcss's Introduction

Tailwind CSS setup to generate just the final css for hosting

The main focus of this repository is just to get the css file for our html in one bundle - CSS/output.css

Follow these steps to get started with tailwindcss:

  1. Install node or npm globally.

  2. Initialize the package.json file

npm init -y      
  1. 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      
  1. Create the tailwind.config.js file
npx tailwindcss init     
  1. 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: [],
}     
  1. 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;  
  1. 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"
  }
}
  1. Create an index.html in root only. Include the output.css, i.e. /CSS/output.css
<link rel="stylesheet" href="/CSS/output.css"> 
  1. Do the npm build
npm run build
  1. To start working on your project do the npm run watch
npm run watch
  1. 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.

generate-final-css-for-hosting-tailwindcss's People

Contributors

apurv-here avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.