PyCharm, Tailwind & htmx

After I shared my initial thoughts on PyCharm, I moved more and more of my projects — personal and work related — to PyCharm. So far, it works out pretty nice, and I am getting more and more accustomed to the IDE. Most of my projects use Django, Tailwind and htmx. While the Django support is great, using Tailwind and htmx needs tweaking.

Tailwind

I already mentioned the required workaround for Tailwind in my initial post. If you have to do it in round about two dozen projects, it turns into a frustrating job. To solve this, I added to new management commands to my django-tailwind-cli package — install_pycharm_workaround and remove_pycharm_workaround. These commands add or remove the package.json file and a link to the CLI.

❯ python manage.py tailwind install_pycharm_workaround
Tailwind CSS CLI already exists at '/Users/oa/.local/bin/tailwindcss-macos-arm64-3.4.13'
Created package.json at '/Users/oa/Projekte/privat/siloga/package.json'
Created link at '/Users/oa/Projekte/privat/siloga/node_modules/tailwindcss/lib/cli.js' to '/Users/oa/.local/bin/tailwindcss-macos-arm64-3.4.13'.

Assure that you have added package.json and node_modules to your .gitignore file.

htmx

Something I always wanted to have in VSCode was highlighting and tooltips for the htmx attributes in my HTML code.

With PyCharm, you can have this! Tobi wrote a great article about this. Just add a statement to the package.json file and drop a file with the htmx web types in your project.

To get both things up and running, I use this package.json in my projects.

{
  "devDependencies": {"tailwindcss": "latest"}, 
  "web-types": "./htmx.web-types.json"
}

Sadly, this is a manual task again. I'm thinking about a simple django package that provides a management command to create this automatically for me. And I plan to make the install_pycharm_workaround management command a bit smarter to support this content of the package.json file.