Tailwind css - using purge successfully?

Does anyone have experience successfully using the purge process for Tailwind’s unused classes? Most of the time, I develop templates locally then upload them through the cli. However, creating modules is easier within Hubspot. Do you usually download the modules so that the purge process can read those files as well?

I tried that but seem to be missing needed classes when viewing the site with the new css file.

Could it be possible that I am not referencing the correct content file paths in my tailwind.config.js file?

Here is what I tested with?

content: [

‘../**/*.html’,

‘../**/**/*.html’,

],

The first path should read all the main folders such as globals, system, and templates. The second path is for the modules folder that was downloaded.

Any suggestions would be greatly appreciated.

Thanks,

Terry McMillan

@Indra , @Oezcan

either of of you mess around with the purging css?

It is a little bit like witchcraft to me :wink:

I have just started toying with converting our css to use tailwind. I am using version 3. With version 3 of tailwind, you do not need to purge as it only generates the classes it finds, and nothing more. Installing Tailwind CSS with Vite - Tailwind CSS So, like you, I like to start off creating the modules within Hubspot to at least establish the editor options and fields. I then fetch the module using the cli, and finish it locally.
My suggestion would be to do that and use the watch command from the Hubspot cli, and also have the tailwind compiler running at the same time. This way, as you are working on your module and saving, you are both uploading your module changes, and tailwind is processing any changes, which in turn get uploaded to hubspot.
For example, in my particular project while working locally, I have initialized a package.json file using node/npm on a level just above the theme. That way, when running the HS watch CLI command on my theme folder, it is not uploading any of that npm stuff. Then, from my package.json, I have a script to get tailwindcss up and running. So I just run those two CLI commands (HS watch and npm) from 2 terminal windows.

Here is an example of the pacakge.json

{

“name”: “tailwind-theme-css”,

“version”: “1.0.0”,

“description”: “CSS for Hubspot theme”,

“scripts”: {

“dev:css”: “tailwindcss -i ./src/myTheme/css/tailwind/input.css -o ./src/myTheme/css/tailwind/output.css --watch”,

},

“devDependencies”: {

@tailwindcss/forms”: “^0.4.0”,

“prettier-plugin-tailwindcss”: “^0.1.4”,

“tailwindcss”: “^3.0.18”

}

}

So, you would want your tailwindcss.config.js file at that root, and depending on your file structure, you will need to adjust the script, but hopefully that get you started?

Again, I am just starting to deal with this myself, but this is my intention in terms of workflow.

As a final note, if you are using VS Code locally, and have installed both the Hubspot VS Code Extensions, and Tailwind CSS Intellisense, you will want to adjust your settings in `.vscode/settings.json` so they play nice together.

{

“files.associations”: {

“*.html”: “html-hubl”,

“*.css”: “css-hubl”

},

“emmet.includeLanguages”: {

“html-hubl”: “html”

},

“tailwindCSS.includeLanguages”: {

“html-hubl”: “html”,

“css-hubl”: “css”

}

}

Great answer! Curious to see how life treats you with tailwind.

@chucktaylor Thanks for the great answer. I will really appreciate you taking the time to respond. Also, thanks for the suggestions on the vscode settings.

It was really bothering me that the purge process didn’t seem to be working correctly. After some research, I discovered it was totally my fault. Lol. My local dev environment did not have the latest versions of the templates on Hubspot. Ugh. I feel stupid I didn’t realize that. In haste, changes had been made on the Hubspot side after going live with the site to fix some issues and I didn’t update my local files. In hindsight, I should have been using hs watch while making the updates locally. Once I made sure I had the latest versions of all my files as well as fetching the modules folder, I re-ran the purge process and it seems to have captured all of the classes being utilized. This took the the css file from 1.8MB (full tailwind) down to 34 KB.

I love using Tailwind CSS and have used it with the last couple of websites we’ve done for clients. Luckily, most of our clients do not require the drag-n-drop sections which I try to avoid at all costs. I have also been trying to minimize my usage of jQuery and testing out Alpine.js as a replacement.

Again, thanks for the response and suggestions.

Terry