Integration utilities for FastAPI and ViteJS.
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
templates = Jinja2Templates(directory='templates')
templates.env.globals['vite_hmr_client'] = fastapi_vite.vite_hmr_client
templates.env.globals['vite_asset'] = fastapi_vite.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
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
fastapi-vite-0.2.3.tar.gz
(5.0 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_vite-0.2.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | babf0ef0e6021cc2617845274996385df529057f05f45592bbc7adb22d01aab3 |
|
MD5 | 141cad29b5aec536dce54b0ee5a76ca9 |
|
BLAKE2b-256 | aa36dabbbb266a54935b42d5bb7e45f75dfc7a2dc96f21ef754070ae6413f7b9 |