Skip to main content

Fork of fastapi-vite to support wider range of jinja2 version.

Project description

fastapi-vite

Integration for FastAPI and Vite JS

what?

This package is designed to make working with javascript assets easier.

fastapi-vite enables the jinja filters required to render asset URLs to jinja templates

Inspired by django-vite @ [https://github.com/MrBin99/django-vite]

installation

Install using pip

pip install fastapi-vite

Usage

Configure Jinja templating for FastAPI

import fastapi_vite_dara

templates = Jinja2Templates(directory='templates')
templates.env.globals['vite_hmr_client'] = fastapi_vite_dara.vite_hmr_client
templates.env.globals['vite_asset'] = fastapi_vite_dara.vite_asset

Configure Vite

Here is an example used to test this plugin

import { defineConfig } from "vite";
import reactRefresh from "@vitejs/plugin-react-refresh";

// const ASSETS_URL = "/static/dist/";

// https://vitejs.dev/config/
export default defineConfig({
  // base: ASSETS_URL,
  clearScreen: false,
  plugins: [reactRefresh()],
  build: {
    target: "esnext",
    outDir: "../static",
    emptyOutDir: true,
    assetsDir: "",
    manifest: true,

    rollupOptions: {
      input: "./assets/javascript/main.tsx",
    },
  },

  root: "assets/", // You can change the root path as you wish
});

Configure Static Assets

Configure Templates

*render_vite_hmr no-op when in production.

{{ render_vite_hmr_client() }}

<script
  type="text/javascript"
  defer
  src="{{ asset_url('javascript/main.tsx') }}"
></script>

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

fastapi_vite_dara-0.3.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

fastapi_vite_dara-0.3.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_vite_dara-0.3.1.0.tar.gz.

File metadata

  • Download URL: fastapi_vite_dara-0.3.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.2 Darwin/24.1.0

File hashes

Hashes for fastapi_vite_dara-0.3.1.0.tar.gz
Algorithm Hash digest
SHA256 bb60a5a61d694eae29a5735eaad3beddced2564e913af1638145faa2742653c4
MD5 ae053844d5370926984bec0548652fdc
BLAKE2b-256 d774ba583d21cd1c0922a6bff4343bdd1158bf63d68bd58263cc9e6e38e67b22

See more details on using hashes here.

File details

Details for the file fastapi_vite_dara-0.3.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_vite_dara-0.3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64feef628a7ccbc6dd1f6e8cddc6c6c39b6bf5edf3891c699c705244208019e9
MD5 00a7119c99f148d09cc083ebd351acd6
BLAKE2b-256 3c67f0d497c57d5a77b4cf9ee813007a3a5c73b7f26c3f42927bdf7869438700

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