A simple package that enables live reload and Tailwind CSS for Flask templates.
Project description
Flask live tailwindcss
A simple package for adding a dev server to your flask app that automatically compiles the tailwindcss of the templates on file save and triggers a browser reload to sync the changes on the fly.
Installation
This package is available on PyPI, you can install it using pip
or other package manager of your choice.
pip install flask-livetw
Its a good practice to add as a development dependency. You can do this by adding the package to your requirements-dev.txt
file or the "dev dependencies" of your package manager.
flask-livetw
Initialization
To start using this package, go to your project folder or the folder where you want to develop. Then run the following command to initialize the package.
livetw init
For default values use the
-d
or--default
flag.
Then where you have your flask app add the following configuration to enable the live reload feature.
import os
...
app.config["LIVETW_DEV"] = os.getenv("LIVETW_ENV") == "development"
When running the flask without livetw dev
during development remember to set the LIVETW_DEV
to True
in your flask app configuration to enable the live reload feature.
app.config["LIVETW_DEV"] = True
For more information on the configuration options see the Configuration section.
Commands
Each command has its own help page, you can use the -h
or --help
flag to see the available options.
dev
livetw dev
By default the command starts:
- a flask server in debug mode
- a live reload websocket server
- a tailwindcss in watch mode
This command sets the enviroment variable LIVETW_ENV
to development
. This is useful for conditional code execution.
build
Builds the Tailwind CSS for the templates into a single CSS file.
livetw build
By default, the built Tailwind CSS file will be minified to reduce the file size. You can disable this feature by using the --no-minify
flag.
livetw build --no-minify
init
Initializes the package in the current directory. Its the command used in Initialization.
livetw init
Configuration
After initialization, a pyproject.toml
file will be created if it does not exist. In this file under the [tool.flask-livetw]
section
This is an example of a configuration file with the default values:
[tool.flask-livetw]
flask_root = "src"
static_folder = "static"
template_folder = "templates"
template_glob = "**/*.html"
base_layout = "layout.html"
livetw_folder = ".dev"
flask_app = "app"
As a file tree, the configuration would look like this:
🌳 project_folder/
┣ 📁 src/
┃ ┣ 📁 static/
┃ ┃ ┣ 📁 .dev/
┃ ┃ ┗ ...
┃ ┣ 📁 templates/
┃ ┃ ┣ 📄 layout.html
┃ ┃ ┗ ...
┃ ┗ ...
┃ 📄 app.py
┣ 📄 pyproject.toml
┗ ...
Main options
flask_root
The root folder of the flask application. All paths are relative to this folder.
Default is "src"
.
flask_app
The argument --app
passed to flask to discover the application. For more information see the Flask Application Discovery documentation.
Default is "app"
.
static_folder
The folder where the static files are stored relative to the flask_root
.
Default is "static"
.
template_folder
The folder where the templates are stored relative to the flask_root
.
Default is "templates"
.
template_glob
The glob pattern to search for templates to build the Tailwind CSS. Must be relative to the template_folder
.
Default is "**/*.html"
.
For more information see the Tailwindcss configuring source paths documentation.
base_layout
The layout that is shared among all templates. This file is used to inject the Tailwind CSS and the live reload script. If it isn't shared among all templates, the Tailwind CSS and the live reload script won't be injected into the templates.
Default is "layout.html"
.
livetw_folder
The folder where flask-livetw stores the related files.
It contains:
global.css
: The global CSS file for the application.live_reload.js
: The live reload script for the application.tailwind_development.css
: The Tailwind CSS file for the application during development.
Default is ".dev"
.
Other options
global_css
The global CSS file for the application relative to the livetw_folder
.
Default is "global.css"
.
tailwind_prod
The production CSS file for the application relative to the static_folder
.
Default is "tailwind_production.css"
.
live_reload_host
The host for websocket server for the live reload functionality. If set must be manually sync on the live reload script for the client.
Default is "127.0.0.1"
.
live_reload_port
The port for websocket server for the live reload functionality. If set must be manually sync on the live reload script for the client.
Default is 5678
.
flask_host
The host for the Flask application.
Default is "127.0.0.1"
.
flask_port
The port for the Flask application.
Default is 5000
.
flask_exclude_patterns
The patterns to exclude python scripts from the Flask application. This is useful to exclude files from triggering the flask server to reload.
Contributing
Contributions are welcome, feel free to submit a pull request or an issue.
Packages used
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file flask_livetw-0.4.3.tar.gz
.
File metadata
- Download URL: flask_livetw-0.4.3.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9642837dbf4eeadf43f665b634134dbc3be250a53ac1961a9d5cc9efaacd021 |
|
MD5 | d81f3a0404785da66f890586de99ee16 |
|
BLAKE2b-256 | 06d9aed06bcc5ac6442a106a28c5119869e254607713f035b2907bbeef8bc01c |
File details
Details for the file flask_livetw-0.4.3-py3-none-any.whl
.
File metadata
- Download URL: flask_livetw-0.4.3-py3-none-any.whl
- Upload date:
- Size: 19.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9277c1a456949fac782446a463ee131f0b36a9e07b29a0fa27df2b9b570a1504 |
|
MD5 | 523438a87f6f86a45fd7de28506ff854 |
|
BLAKE2b-256 | f64e48ef9b39ea49d19b22ca5e1847048a933600a157a299dd23ec5b2c8023f6 |