Skip to main content

Provides a CLI plugin for Litestar to use Tailwind CSS via the Tailwind CLI.

Project description

litestar-tailwind

forked from Tobi-De/litestar-tailwind-cli with improves

PyPI - Version PyPI - Python Version


[!IMPORTANT] This plugin currently contains minimal features and is a work-in-progress

Provides a CLI plugin for Litestar to use Tailwind CSS via the Tailwind CLI.

Table of Contents

Installation

pip install litestar-tailwind

Usage

Configure and include the TailwindCLIPlugin in your Litestar app:

from pathlib import Path

from litestar import Litestar
from litestar.static_files import create_static_files_router
from litestar.contrib.jinja import JinjaTemplateEngine
from litestar.template.config import TemplateConfig
from litestar_tailwind_cli import TailwindCLIPlugin

ASSETS_DIR = Path("assets")

tailwind_cli = TailwindCLIPlugin(
  use_server_lifespan=True,
  src_css=ASSETS_DIR / "css" / "input.css",
  dist_css=ASSETS_DIR / "css" / "tailwind.css",
)

app = Litestar(
    route_handlers=[create_static_files_router(path="/static", directories=["assets"])],
    debug=True,
    plugins=[tailwind_cli],
    template_config=TemplateConfig(
        directory=Path("templates"),
        engine=JinjaTemplateEngine,
    ),
)
<head>
...
  <link rel="stylesheet" href="/static/css/tailwind.css">
</head>

After setting up, you can use the following commands:

  • litestar tailwind init: This command initializes the tailwind configuration and downloads the CLI if it's not already installed.
  • litestar tailwind watch: This command starts the Tailwind CLI in watch mode during development. You won't have to use this if you set use_server_lifespan to True.
  • litestar tailwind build: This command builds a minified production-ready CSS file.

[!NOTE] Don't forget to update the content key in tailwind.config.js to specify your templates directories.

The TailwindCLIPlugin has the following configuration options:

  • src_css: The path to the source CSS file. Defaults to "css/input.css".
  • dist_css: The path to the distribution CSS file. Defaults to "css/tailwind.css".
  • config_file: The path to the Tailwind configuration file. Defaults to "tailwind.config.js".
  • use_server_lifespan: Whether to use server lifespan. Defaults to False. It will start the Tailwind CLI in watch mode when you use the litestar run command.
  • conventional_path_resolve: Only use the existing implementation for Tailwind CLI searches. defaults to True.
  • cli_version: The version of the Tailwind CLI to download. Defaults to "latest".
  • src_repo: The GitHub repository from which to download the Tailwind CLI. Defaults to tailwindlabs/tailwindcss.
  • asset_name: The name of the asset to download from the repository. Defaults to tailwindcss.

For example, if you are using the repository https://github.com/dobicinaitis/tailwind-cli-extra/tree/main, you would set src_repo to "dobicinaitis/tailwind-cli-extra" and asset_name to "tailwindcss-extra".

License

litestar-tailwind and litestar-tailwind-cli (original library) is distributed under the terms of the MIT license. is distributed under the terms of the MIT license.

Changes from Original

  • litestar-tailwind now supports tailwindcss v4. v3 is no longer supported.
  • You can now use {% tailwind_css() %} to get the location of TailwindCSS's dist CSS. However, TailwindCSS files must be located under the web server's URI, static.
  • By using {% load_tailwind() %}, you can now automatically load TailwindCSS. However, the same requirements apply as when using {% tailwind_css() %}.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

litestar_tailwind-0.2.1.tar.gz (113.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

litestar_tailwind-0.2.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file litestar_tailwind-0.2.1.tar.gz.

File metadata

  • Download URL: litestar_tailwind-0.2.1.tar.gz
  • Upload date:
  • Size: 113.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.21

File hashes

Hashes for litestar_tailwind-0.2.1.tar.gz
Algorithm Hash digest
SHA256 968d8a094a009784ec6850fb2ff61dbc256640446148b14b0fe79a4b89848020
MD5 3bf90e2411ade513b3092f25e68dccdb
BLAKE2b-256 4070845cad032fdb7960817b45d5a2b18c3cbea7ea6e0d156aa7f249354bcb09

See more details on using hashes here.

File details

Details for the file litestar_tailwind-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for litestar_tailwind-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3f6fe3664391abe1cc10772f26a5dbc812ded5e6f25298f9a3a9f64a1873a25c
MD5 d89fb767a6ac5656fe266047c7f7647d
BLAKE2b-256 651f31cbe1467ad846cee492cf9f69ccf4a84e1e8d6dfcff0b00834d66d7158f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page