Skip to content

Commit a839d2f

Browse files
committed
Tailwind CSS 4.0 support.
1 parent bf91adb commit a839d2f

20 files changed

+1665
-1260
lines changed

CHANGELOG.md

+34-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
# Changelog
22

3+
## 4.0.0
4+
5+
- Added support for Tailwind CSS 4.0.0.
6+
- Default version is Tailwind CSS 4.0.0.
7+
- The versioning is now aligned with Tailwind CSS. That means the major number of this packages
8+
follows the major number of Tailwind CSS to document the most recent support version of it.
9+
- Removed the management commands `install_pycharm_workaround` and `uninstall_pycharm_workaround`.
10+
This feature broke too often.
11+
- Removed `runserver_plus` subcommand. The management subcommand `runserver` now starts either the
12+
debug server from django-extensions if this package is installed. Otherwise it starts the standard
13+
debug server.
14+
- The management subcommand `runserver` has a option `--force-default-runserver` to enforce the
15+
usage of the standard debug server from Django.
16+
- `TAILWIND_CLI_CONFIG_FILE` isn't necessary for Tailwind CSS 4.x only for 3.x.
17+
[Read the documentaiton about it.](settings.md)
18+
- Removed the documentation for the fancier `tailwind.config.js` as it is not recommended to use
19+
and Tailwind CSS 4.x has a way better strategy to find the used Tailwind classes.
20+
321
## 2.21.1
422

523
- Relaxed the minimum Django version to >=4.0.
624

725
## 2.21.0
826

9-
- Added `install_pycharm_workaround` and `remove_pycharm_workaround` management commands. [#142](https://github.com/django-commons/django-tailwind-cli/issues/142)
10-
- Added `remove_cli` subcommand to remove the CLI. [#132](https://github.com/django-commons/django-tailwind-cli/issues/132)
27+
- Added `install_pycharm_workaround` and `remove_pycharm_workaround` management commands.
28+
[#142](https://github.com/django-commons/django-tailwind-cli/issues/142)
29+
- Added `remove_cli` subcommand to remove the CLI.
30+
[#132](https://github.com/django-commons/django-tailwind-cli/issues/132)
1131
- Refactored all the class based management command into simpler function based commands.
1232
- Refactored the process to build the runserver command.
1333

@@ -43,7 +63,8 @@
4363

4464
## 2.17.0
4565

46-
- Internal refactoring. Config class has been replaced with django-appconfig and some function in the django_tailwind_cli.utils package.
66+
- Internal refactoring. Config class has been replaced with django-appconfig and some function in
67+
the django_tailwind_cli.utils package.
4768
- uv is used for publishing too.
4869
- Updated tooling configuration.
4970

@@ -56,17 +77,21 @@
5677

5778
## 2.15.0
5879

59-
- [#130](https://github.com/oliverandrich/django-tailwind-cli/pull/130) by [@Tobi-De](https://github.com/Tobi-De) extended the support for custom tailwind cli builds. See `TAILWIND_CLI_SRC_REPO` and `TAILWIND_CLI_ASSET_NAME` in the documentation.
80+
- [#130](https://github.com/oliverandrich/django-tailwind-cli/pull/130) by
81+
[@Tobi-De](https://github.com/Tobi-De) extended the support for custom tailwind cli builds. See
82+
`TAILWIND_CLI_SRC_REPO` and `TAILWIND_CLI_ASSET_NAME` in the documentation.
6083

6184
## 2.14.0
6285

63-
- [#129](https://github.com/oliverandrich/django-tailwind-cli/pull/129) by [@Tobi-De](https://github.com/Tobi-De) add a setting to allow for custom tailwind source repo
86+
- [#129](https://github.com/oliverandrich/django-tailwind-cli/pull/129) by
87+
[@Tobi-De](https://github.com/Tobi-De) add a setting to allow for custom tailwind source repo
6488
- Bumped default version of tailwindcss to 3.4.10.
6589

6690
## 2.13.0
6791

68-
- [#127](https://github.com/oliverandrich/django-tailwind-cli/pull/127)
69-
by [@bckohan](https://github.com/bckohan) upgrade django-typer and fixed future incompatibilities with django-typer 3.0.
92+
- [#127](https://github.com/oliverandrich/django-tailwind-cli/pull/127) by
93+
[@bckohan](https://github.com/bckohan) upgrade django-typer and fixed future incompatibilities
94+
with django-typer 3.0.
7095
- moved to tox for testing.
7196
- Added Python 3.13 to the test matrix.
7297
- Added Django 5.1a1 to the test matrix.
@@ -93,7 +118,8 @@
93118
## 2.9.0
94119

95120
- Bumped default Tailwind CLI version to 3.4.1.
96-
- Reimplemented the management command using [django_typer](https://django-typer.readthedocs.io/en/stable/)
121+
- Reimplemented the management command using
122+
[django_typer](https://django-typer.readthedocs.io/en/stable/)
97123
- Removed Python 3.8 from the list of supported versions.
98124

99125
## 2.8.1

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Checkout the detailed [installation guide](https://django-tailwind-cli.rtfd.io/l
6262
## Features
6363

6464
- Simplest possible integration.
65+
- Support Tailwind CSS 3.x and 4.x.
6566
- Management commands:
6667

6768
* To start the Tailwind CLI in watch mode during development.
@@ -71,7 +72,7 @@ Checkout the detailed [installation guide](https://django-tailwind-cli.rtfd.io/l
7172
- Configuration options to adapt the library to your project, when the defaults don't fit you.
7273
- A template tag to include the Tailwind CSS file in your project.
7374
- A base template for your project.
74-
- A sane tailwind.config.js that activates all the official plugins and includes a simple HTMX plugin.
75+
- Sane default configurations for Tailwind 3.x and Tailwinc 4.x.
7576
- A management command to install [a workaround to support Tailwind CLI in PyCharm](https://django-tailwind-cli.rtfd.io/latest/usage/#use-with-pycharm).
7677

7778
## Requirements

docs/installation.md

+6-18
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ hide:
1010
1. Install the library.
1111

1212
```shell
13-
python -m pip install django-tailwind-cli
13+
python -m pip install "django-tailwind-cli"
1414
```
1515

16-
with optional `django-extensions` and `Werkezeug` libraries to use the `runserver_plus` command.
16+
Add the optional libraries `django-extensions` and `Werkzeug` to use the extended debug server
17+
from `django-extensions`.
1718

1819
```shell
19-
python -m pip install django-tailwind-cli[django-extensions]
20+
python -m pip install "django-tailwind-cli[django-extensions]"
2021
```
2122

2223
2. Add `django_tailwind_cli` to `INSTALLED_APPS` in `settings.py`.
@@ -28,7 +29,8 @@ hide:
2829
]
2930
```
3031

31-
If you plan to use the `runserver_plus` command, the changes to `INSTALLED_APPS` looks like that.
32+
If you want to use the extended debug server from `django-extensions`, add the package to the
33+
installed apps.
3234

3335
```python
3436
INSTALLED_APPS = [
@@ -64,12 +66,6 @@ hide:
6466

6567
Or
6668

67-
```shell
68-
python manage.py tailwind runserver_plus
69-
```
70-
71-
Or
72-
7369
```shell
7470
python manage.py tailwind watch
7571
```
@@ -78,14 +74,6 @@ hide:
7874

7975
## Optional steps
8076

81-
### Install PyCharm workaround
82-
83-
In order [to use Tailwind CLI with PyCharm](/usage/#use-with-pycharm) you have to install a workaround.
84-
85-
```shell
86-
python manage.py tailwind install_pycharm_workaround
87-
```
88-
8977
### Install `django-browser-reload`
9078

9179
If you enjoy automatic reloading during development. Install the [django-browser-reload](https://github.com/adamchainz/django-browser-reload) app. The following installation steps are taken from the README of the project.

docs/settings.md

+19-76
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The package can be configured by a few settings, which can be overwritten in the
1111
your project.
1212

1313
`TAILWIND_CLI_VERSION`
14-
: **Default**: `"3.4.13"`
14+
: **Default**: `"4.0.0"`
1515

1616
This defines the version of the CLI and of Tailwind CSS you want to use in your project.
1717

@@ -64,23 +64,35 @@ your project.
6464
Enable or disable the automatic downloading of the official CLI to your machine.
6565

6666
`TAILWIND_CLI_SRC_CSS`
67-
: **Default**: `None`
67+
: **Default** (for Tailwind 3.x): `None`<br>**Default** (for Tailwind 4.x): `css/source.css`
6868

69-
The name of the optional input file for the Tailwind CLI, where all the directivces and custom styles are defined. This is where you add your own definitions for the different layers.
69+
!!! warning
70+
This setting is optional for Tailwind CSS 3.x. For Tailwind CSS 4.x it must not be empty.
71+
72+
For **Tailwind CSS 3.x** this optional file is used to define addition CSS rules for your project.
7073

71-
If you don't define this setting, the default of the Tailwind CLI is used.
74+
For **Tailwind CSS 4.x** this required file is used to configure Tailwind CSS and also add
75+
additional CSS rules for your project. This file is stored relative to the first element of
76+
the `STATICFILES_DIRS` array.
7277

7378
`TAILWIND_CLI_DIST_CSS`
7479
: **Default**: `"css/tailwind.css"`
7580

76-
The name of the output file. This file is stored relative to the first element of the `STATICFILES_DIRS` array.
81+
The name of the output file. This file is stored relative to the first element of the
82+
`STATICFILES_DIRS` array.
7783

7884
`TAILWIND_CLI_CONFIG_FILE`
7985
: **Default**: `"tailwind.config.js"`
8086

81-
The name of the Tailwind CLI config file. The file is stored relative to the `BASE_DIR` defined in your settings.
87+
!!! danger
88+
89+
Is only required for Tailwind CSS 3.x. If you use it with Tailwind CSS 4.x, it is ignored
90+
and also raises an exception to force you to remove it.
8291

83-
## `tailwind.config.js`
92+
The name of the Tailwind CLI config file. The file is stored relative to the `BASE_DIR` defined
93+
in your settings.
94+
95+
## `tailwind.config.js` (Tailwind CSS 3.x only)
8496

8597
If you don't create a `tailwind.config.js` file yourself, the management commands will create a sane default for you inside the `BASE_DIR` of your project. The default activates all the official plugins for Tailwind CSS and adds a minimal plugin to support some variants for [HTMX](https://htmx.org/).
8698

@@ -109,72 +121,3 @@ module.exports = {
109121
],
110122
};
111123
```
112-
113-
### Fancier version of `tailwind.config.js`
114-
115-
This configuration also embraces the nice trick authored by Carlton Gibson in his post [Using Django’s template loaders to configure Tailwind¶](https://noumenal.es/notes/tailwind/django-integration/). The implementation adopts Carlton's implementation to honor the conventions of this project. If you put your `tailwind.config.js` in a different location than your `BASE_DIR`, you have to change this file too.
116-
117-
This configuration uses the management command `tailwind list_templates`, which list all the templates files inside your project.
118-
119-
!!! warning "Editor Integration besides VS Code"
120-
121-
The following default configuration tries to be as smart as possible to find all the templates inside your project and installed dependencies. This works like a charm when you run the debug server using `python manage.py tailwind runserver`. It also works if you start VSCode with `code .` from within the active virtual environment.
122-
123-
But it does not work with Sublime Text and the lsp-tailwindcss package or with the various LSP packages for (neo)vim. The reason is, that these intergrations not honoring the active virtual environment when being started. If you have an idea to solve this, patches are welcome.
124-
125-
**With editors besides VS Code please use the default config.**
126-
127-
```javascript title="tailwind.config.js"
128-
/** @type {import('tailwindcss').Config} */
129-
const plugin = require("tailwindcss/plugin");
130-
const { spawnSync } = require("child_process");
131-
132-
// Calls Django to fetch template files
133-
const getTemplateFiles = () => {
134-
const command = "python3";
135-
const args = ["manage.py", "tailwind", "list_templates"];
136-
// Assumes tailwind.config.js is located in the BASE_DIR of your Django project.
137-
const options = { cwd: __dirname };
138-
139-
const result = spawnSync(command, args, options);
140-
141-
if (result.error) {
142-
throw result.error;
143-
}
144-
145-
if (result.status !== 0) {
146-
console.log(result.stdout.toString(), result.stderr.toString());
147-
throw new Error(
148-
`Django management command exited with code ${result.status}`
149-
);
150-
}
151-
152-
const templateFiles = result.stdout
153-
.toString()
154-
.split("\n")
155-
.map((file) => file.trim())
156-
.filter(function (e) {
157-
return e;
158-
}); // Remove empty strings, including last empty line.
159-
return templateFiles;
160-
};
161-
162-
module.exports = {
163-
content: [].concat(getTemplateFiles()),
164-
theme: {
165-
extend: {},
166-
},
167-
plugins: [
168-
require("@tailwindcss/typography"),
169-
require("@tailwindcss/forms"),
170-
require("@tailwindcss/aspect-ratio"),
171-
require("@tailwindcss/container-queries"),
172-
plugin(function ({ addVariant }) {
173-
addVariant("htmx-settling", ["&.htmx-settling", ".htmx-settling &"]);
174-
addVariant("htmx-request", ["&.htmx-request", ".htmx-request &"]);
175-
addVariant("htmx-swapping", ["&.htmx-swapping", ".htmx-swapping &"]);
176-
addVariant("htmx-added", ["&.htmx-added", ".htmx-added &"]);
177-
}),
178-
],
179-
};
180-
```

0 commit comments

Comments
 (0)