Alaa
Alaa

Reputation: 428

running tailwind / postcss

I'm trying to install Tailwind to practice some basic stuff to learn how this framework works. I followed every step that Adam Wathan the creator of the framework provided and when it comes to running I face command line error: You must pass a valid list of files to parse. Also I faced a an error while defining tailwind custom markers

@tailwind base;
@tailwind components;
@tailwind utilities;

first it says unknown at rule @tailwind, then after installing stylelint and following @hasusuf answer Steps I followed

another error showing up! enter image description here

and the same command error is still there.

Any help ?

Upvotes: 3

Views: 8395

Answers (2)

hakki
hakki

Reputation: 6517

This answer is outdated. Newer versions of tailwind support JIT as default

Giorgio Tempesta's steps are correct but need to improve for best performance.

Follow below steps for live output to your output css file with JIT mode (Just in time). So when you working on your project you don't need to compile source css file manually. Also JIT mode brings dynamic class implementations like bg-[#abcaaa]

in your package.json file add these to scripts area like

 "scripts": {
    "watch-tailwind": "npx tailwindcss -i source.css -o output.css -w --minify",
    "build-tailwind": "npx tailwindcss -i source.css -o output.css --minify"
  },

Flag meanings;

-i:input file
-o:output file
-w:watch changes
--minify: minify output css file
  • source.css is your main ang gigantic source css file.
  • output.css is your just in time compiled and minified css file.

Also your tailwind.config.css file should look basically like this

module.exports = {
  mode: "jit", <------------ add this for immediate compile
  purge: ["./src/**/*.html", "./src/**/*.js"], <--- give here your source files
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
};

After saved this settings on your package.json run;

npm run watch-tailwind

When you run this npm script, tailwind starts to listen changes in your project and output ONLY necessary css declarations to your output.css

It's huge difference. Before you doing above steps your css file is nearly 18MB

After compiling it's nearly 20-30KB

See JIT mode in action: https://tailwindcss.com/docs/just-in-time-mode

This is new era for tailwind.

Note: JIT mode available on v2.1+

Upvotes: 4

Giorgio Tempesta
Giorgio Tempesta

Reputation: 2059

Today I tried installing Tailwind in the most basic way and it worked. I took most information from https://tailwindcss.com/docs/installation/ but if you're not experienced with build tools you can get lost in the last part.

Here are the steps:

1. Create index.html and styles.css files

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="output.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="flex container mx-auto justify-center">
        <button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded mt-8">
            Button
        </button>
    </div>
</body>
</html>

Note that the link tag is pointing to output.css and not styles.css (we'll see why in a minute).

styles.css

@tailwind base;

@tailwind components;

@tailwind utilities;

2. Initialize npm from the command line and pick the default config

npm init -y or npm init and answer to all the questions.

3. Install Tailwind from the command line

npm install tailwindcss

4. Initialize a basic Tailwind config

npx tailwindcss init

5. Build your css file

npx tailwindcss build styles.css -o output.css

Here the code you have written in styles.css will output in output.css.

6. You're done

Open index.html from your browser and edit the html or css file. Note that every change you make on the css file needs a new build (#5).

This is not the better configuration but it's a start.

Upvotes: 9

Related Questions