Utility for writing frontend plugins for Datasette with Vite
Project description
datasette-vite
Utility for writing frontend plugins for Datasette with Vite
Installation
Install this plugin in the same environment as Datasette.
datasette install datasette-vite
Usage
This plugin provides a vite_entry() function that other Datasette plugins can use to include Vite-built JavaScript and CSS assets in their pages.
Setting up your plugin
Your plugin needs a Vite project alongside its Python code. Configure vite.config.ts to output a manifest and place built files in a static/ directory:
// vite.config.ts
import { defineConfig } from 'vite'
export default defineConfig({
build: {
manifest: true,
outDir: 'dist',
rollupOptions: {
input: 'src/main.ts',
output: {
assetFileNames: 'static/[name]-[hash][extname]',
chunkFileNames: 'static/[name]-[hash].js',
entryFileNames: 'static/[name]-[hash].js',
}
}
}
})
After running vite build, copy dist/.vite/manifest.json and dist/static/ into your plugin's Python package directory so they are included when your plugin is installed.
Using vite_entry() in your plugin
from datasette_vite import vite_entry
entry = vite_entry(
datasette=datasette,
plugin_package="my_datasette_plugin",
)
html = await entry("src/main.ts")
The returned html string contains <script> and <link> tags ready to include in your page:
<link rel="stylesheet" href="/-/static-plugins/my_datasette_plugin/main-def456.css">
<script type="module" src="/-/static-plugins/my_datasette_plugin/main-abc123.js"></script>
Development mode
During development, pass vite_dev_path to point at a running Vite dev server instead of reading from the manifest. This enables hot module replacement:
entry = vite_entry(
datasette=datasette,
plugin_package="my_datasette_plugin",
vite_dev_path="http://localhost:5173/",
)
html = await entry("src/main.ts")
This produces:
<script type="module" src="http://localhost:5173/@vite/client"></script>
<script type="module" src="http://localhost:5173/src/main.ts"></script>
API reference
vite_entry(datasette, plugin_package, vite_dev_path=None, manifest_dir=None)
datasette: The Datasette instance.plugin_package: The Python package name of your plugin (used to resolve the manifest location and generate static asset URLs).vite_dev_path: Optional URL to a running Vite dev server (e.g."http://localhost:5173/"). When set, assets are served from the dev server instead of from built files.manifest_dir: Optional path to the directory containingmanifest.json. Defaults to the directory of your plugin package's__init__.py.
Returns an async callable. Call it with an entrypoint path (matching a key in your Vite manifest) to get an HTML string of the corresponding <script> and <link> tags.
Development
To set up this plugin locally, first checkout the code. You can confirm it is available like this:
cd datasette-vite
# Confirm the plugin is visible
uv run datasette plugins
To run the tests:
uv run pytest
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datasette_vite-0.0.1a2.tar.gz.
File metadata
- Download URL: datasette_vite-0.0.1a2.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dc315a71e13e01f09eefe550c183f84d18458c4bdc9404debb38ffee794daba
|
|
| MD5 |
42b675ce20e4a11988b4b876953c6508
|
|
| BLAKE2b-256 |
deb63d672c02f037895470ebd9a0a45ec0b65eee044a50d5327a7b3765fa0d6a
|
Provenance
The following attestation bundles were made for datasette_vite-0.0.1a2.tar.gz:
Publisher:
publish.yml on datasette/datasette-vite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
datasette_vite-0.0.1a2.tar.gz -
Subject digest:
3dc315a71e13e01f09eefe550c183f84d18458c4bdc9404debb38ffee794daba - Sigstore transparency entry: 1117387728
- Sigstore integration time:
-
Permalink:
datasette/datasette-vite@b315690c3a56fb24475c4f900e8bc06d6b28e30a -
Branch / Tag:
refs/tags/0.0.1a2 - Owner: https://github.com/datasette
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b315690c3a56fb24475c4f900e8bc06d6b28e30a -
Trigger Event:
release
-
Statement type:
File details
Details for the file datasette_vite-0.0.1a2-py3-none-any.whl.
File metadata
- Download URL: datasette_vite-0.0.1a2-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e57ac96798cf83b753f0010345f1f89def46fc29d746ebda5d8424351f6a561
|
|
| MD5 |
a46f7fd7e004658b1f720148154146d5
|
|
| BLAKE2b-256 |
d043b43e00f6c67df7450952fa05e58e86eb27fa971336c4fb47a73106db65ad
|
Provenance
The following attestation bundles were made for datasette_vite-0.0.1a2-py3-none-any.whl:
Publisher:
publish.yml on datasette/datasette-vite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
datasette_vite-0.0.1a2-py3-none-any.whl -
Subject digest:
0e57ac96798cf83b753f0010345f1f89def46fc29d746ebda5d8424351f6a561 - Sigstore transparency entry: 1117387730
- Sigstore integration time:
-
Permalink:
datasette/datasette-vite@b315690c3a56fb24475c4f900e8bc06d6b28e30a -
Branch / Tag:
refs/tags/0.0.1a2 - Owner: https://github.com/datasette
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b315690c3a56fb24475c4f900e8bc06d6b28e30a -
Trigger Event:
release
-
Statement type: