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.1.tar.gz
(5.1 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_vite-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 539a5e468f62aff296a789e192f372c22a414292f0a513d6a7db5148884fbeac |
|
MD5 | cac3406ac6df0aaef2cc683067df55ea |
|
BLAKE2b-256 | 411032cfdd1044b05134791cf5e66648390232a0260486aaac69e4fdc76e04c7 |