Loader

litestar_vite.loader.render_hmr_client(context: Mapping[str, Any], /) Markup[source]

Render the HMR client.

Parameters:

context – The template context.

Returns:

The HMR client.

litestar_vite.loader.render_asset_tag(context: Mapping[str, Any], /, path: str | list[str], scripts_attrs: dict[str, str] | None = None) Markup[source]

Render an asset tag.

Parameters:
  • context – The template context.

  • path – The path to the asset.

  • scripts_attrs – The attributes for the script tag.

Returns:

The asset tag.

class litestar_vite.loader.ViteAssetLoader[source]

Bases: object

Vite manifest loader.

Please see: https://vitejs.dev/guide/backend-integration.html

__init__(config: ViteConfig) None[source]
classmethod initialize_loader(config: ViteConfig) ViteAssetLoader[source]

Singleton manifest loader.

render_hmr_client() Markup[source]

Generate the script tag for the Vite WS client for HMR.

render_asset_tag(path: str | list[str], scripts_attrs: dict[str, str] | None = None) Markup[source]

Generate all assets include tags for the file in argument.

parse_manifest() None[source]

Parse the Vite manifest file.

The manifest file is a JSON file that maps source files to their corresponding output files. Example manifest file structure:

{
    "main.js": {
        "file": "assets/main.4889e940.js",
        "src": "main.js",
        "isEntry": true,
        "dynamicImports": ["views/foo.js"],
        "css": ["assets/main.b82dbe22.css"],
        "assets": ["assets/asset.0ab0f9cd.png"]
    },
    "views/foo.js": {
        "file": "assets/foo.869aea0d.js",
        "src": "views/foo.js",
        "isDynamicEntry": true,
        "imports": ["_shared.83069a53.js"]
    },
    "_shared.83069a53.js": {
        "file": "assets/shared.83069a53.js"
    }
}

The manifest is parsed and stored in memory for asset resolution during template rendering.

generate_ws_client_tags() str[source]

Generate the script tag for the Vite WS client for HMR.

Only used when hot module reloading is enabled, in production this method returns an empty string.

Returns:

The script tag or an empty string.

Return type:

str

generate_react_hmr_tags() str[source]

Generate the script tag for the Vite WS client for HMR.

Only used when hot module reloading is enabled, in production this method returns an empty string.

Returns:

The script tag or an empty string.

Return type:

str

generate_asset_tags(path: str | list[str], scripts_attrs: dict[str, str] | None = None) str[source]

Generate all assets include tags for the file in argument.

Returns:

All tags to import this asset in your HTML page.

Return type:

str