Each time I add a new class to the index.html
file, I need to rebuild the output.css
file manually.
The package.json file:
{
"name": "tailwind-practice",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "npx tailwindcss --watch -i ./input.css -o ./output.css"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"tailwindcss": "^3.1.7"
}
}
The tailwind.config.js file:
/** @type {import('tailwindcss').Config} */
module.exports = {
screens: {
'sm': '480px',
'md': '768px',
'lg': '1440px',
},
content: ['./index.html'],
theme: {
extend: {},
},
plugins: [],
}
I am supposed to run npm run build
once, and each time I saved the html file, tailwind is supposed to add my new classes to output.css
. But it doesn’t. I checked the file after saving index.html
and I couldn’t find my new classes there. But the CLI shamelessly said it rebuilt it in 20ms. I needed to run npm run build
each time to successfully build my css file. Also, I deleted my previous nodejs installation and reinstalled the current version, updated VS Code, updated Google Chrome, and now, I am considering moving back to Windows from Manjaro.
Edit: A useful observation.
After saving index.html
, the CLI said this:
Rebuilding...
Done in 27ms.
But when I stopped the process and reran npm run build
, it said:
Rebuilding...
Done in 198ms.
There is a relatively huge time delay when it actually works.
Edit 2:
It works when I save index.html
multiple times rapidly.
I moved from Manjaro to Ubuntu, and it still doesn’t work!
3
Answers
Assuming this is how you think Tailwind CLI works:
input.css
:index.html
:npm run build
index.html
and add an HTML element with some Tailwind classoutput.css
to be magically built into this:This is how Tailwind CLI actually works:
input.css
you have to first specify which Tailwind layers you think you will use in yourindex.html
. Let’s add a layer calledutilities
which enables you to use Tailwind classes such asfont-bold
,underline
, etc.npm run build
index.html
and add an HTML element with some Tailwind class which belongs to theutilities
layeroutput.css
et voila – the Tailwind class is there:utilities
layeret voila:
You need to add these to your input.css to make the
--watch
work properly.Without these, TW won’t know from where it should pull info for your CSS classes and write a processed version in output.css
Let’s say you wrote
<h1 class="underline">Hello world! </h1>
inindex.html
.Tw needs to look for information on how it can parse + process the
underline
class and what should be written in output.css regarding this class.Try it and let me know if it works.
try changing
from
to