Skip to main content

Easily integrate Python, Flask and Vite

Project description

Vite Fusion: Integrating Vite with Flask

Author: Claudio González © 2024 Banshee
Website: https://www.banshee.pro/
License: MIT License


This module provides functions to register and serve Vite generated assets in Flask applications. It supports both the Vite development server and production environments using the manifest.json file.


Table of Contents


Installation

  1. Install the required dependencies for Flask and Vite.
  2. Copy the register_vite_assets function into your project.

Usage

After initializing your Flask application, call the register_vite_assets function to integrate Vite assets.

Example Usage:

from vite_fusion import register_vite_assets

app = Flask(__name__)

register_vite_assets(
    app,
    dev_mode=True,
    dev_server_url="http://localhost:5173",
    manifest_path="src/dist/.vite/manifest.json",
    nonce_provider=my_nonce_provider,  # Optional
    logger=my_logger                   # Optional
)

Parameters

Parameter Type Description Default Value
app Flask The Flask application instance. Required
dev_mode bool Indicates if the Vite development server is running. True
dev_server_url str URL of the Vite development server (e.g., http://localhost:5173). "http://localhost:5173"
manifest_path str Path to the production manifest.json generated by Vite. "src/dist/.vite/manifest.json"
nonce_provider callable or None Function returning a nonce (string) for CSP headers. If None, no nonce attribute is added. None
logger logging.Logger or None Logger instance for errors and warnings. If None, logging is disabled. None

manifest.json in dev mode?

Although accessing the manifest.json file in development mode is not a common practice, we concluded that searching for and loading files directly from it in development mode, without needing to set up an array of files, is the most appropriate approach. As a result, the manifest.json file must be available in both development and production environments. This is why we recommend running npm run build before starting to use this integration.


Examples

Registering Vite Assets in Development Mode

register_vite_assets(
    app,
    dev_mode=True,
    dev_server_url="http://localhost:5173",
    manifest_path="src/dist/.vite/manifest.json"
)

Registering Vite Assets in Production Mode

register_vite_assets(
    app,
    dev_mode=False,
    manifest_path="src/dist/.vite/manifest.json",
    nonce_provider=my_nonce_provider
)

or

register_vite_assets(
    homedock_www,
    dev_mode=False,
    manifest_path="src/dist/.vite/manifest.json",
    nonce_provider=nonce_value,
    logger=None
)

License

This project is licensed under the MIT License. See the LICENSE file for details.


About This Integration

This integration was created to work seamlessly with our project, HomeDock OS. HomeDock OS is a powerful and flexible platform for home automation and cloud management. Learn more at homedock.cloud.


Contributing and Support

Feel free to fork this repository and contribute! For any bug fixes, security concerns, or other issues, please email us at claudio@banshee.pro.

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

vite_fusion-0.0.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

vite_fusion-0.0.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file vite_fusion-0.0.2.tar.gz.

File metadata

  • Download URL: vite_fusion-0.0.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.6

File hashes

Hashes for vite_fusion-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b3402a30b05111e2a919b9448e945f7795822db7f2858ddcc73d1d05489974f3
MD5 f087c7795f585a49ce58842df0566f49
BLAKE2b-256 0fb2b8e0610606ddef589966a658d091aba7c69815579b0ebaf236081ae02c55

See more details on using hashes here.

File details

Details for the file vite_fusion-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: vite_fusion-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.6

File hashes

Hashes for vite_fusion-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 40b409d09b294a0b3785a74ea701043820598e878b9995bf22986d0e791c1683
MD5 4ace626244cc7b5b6d18e06c3169255a
BLAKE2b-256 99532a197cce61fbeb7358cc1c5eafd608cacbce13165878caeef54c5af5a975

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