litestar-vite


Namelitestar-vite JSON
Version 0.11.1 PyPI version JSON
download
home_pageNone
SummaryVite plugin for Litestar
upload_time2024-12-09 03:01:05
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords litestar vite
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Litestar Vite

## Installation

```shell
pip install litestar-vite
```

## Usage

Here is a basic application that demonstrates how to use the plugin.

```python
from __future__ import annotations

from pathlib import Path

from litestar import Controller, get, Litestar
from litestar.response import Template
from litestar.status_codes import HTTP_200_OK
from litestar.template.config import TemplateConfig
from litestar.contrib.jinja import JinjaTemplateEngine
from litestar_vite import ViteConfig, VitePlugin

class WebController(Controller):

    opt = {"exclude_from_auth": True}
    include_in_schema = False

    @get(["/", "/{path:str}"],status_code=HTTP_200_OK)
    async def index(self) -> Template:
        return Template(template_name="index.html.j2")

template_config = TemplateConfig(engine=JinjaTemplateEngine(directory='templates/'))
vite = VitePlugin(config=ViteConfig())
app = Litestar(plugins=[vite], template_config=template_config, route_handlers=[WebController])

```

Create a template to serve the application in `./templates/index.html.h2`:

```html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <!--IE compatibility-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0"
    />
  </head>

  <body>
    <div id="app"></div>
    {{ vite_hmr() }} {{ vite('resources/main.ts') }}
  </body>
</html>
```

### Template initialization (Optional)

This is a command to help initialize Vite for your project. This is generally only needed a single time. You may also manually configure Vite and skip this step.

to initialize a Vite configuration:

```shell
❯ litestar assets init
Using Litestar app from app:app
Initializing Vite ──────────────────────────────────────────────────────────────────────────────────────────
Do you intend to use Litestar with any SSR framework? [y/n]: n
INFO - 2023-12-11 12:33:41,455 - root - commands - Writing vite.config.ts
INFO - 2023-12-11 12:33:41,456 - root - commands - Writing package.json
INFO - 2023-12-11 12:33:41,456 - root - commands - Writing tsconfig.json
```

### Install Javascript/Typescript Packages

Install the packages required for development:

**Note** This is equivalent to the the `npm install` by default. This command is configurable.

```shell
❯ litestar assets install
Using Litestar app from app:app
Starting Vite package installation process ──────────────────────────────────────────────────────────────────────────────────────────

added 25 packages, and audited 26 packages in 1s


5 packages are looking for funding
  run `npm fund` for details


found 0 vulnerabilities
```

### Development

To automatically start and stop the Vite instance with the Litestar application, you can enable the `use_server_lifespan` hooks in the `ViteConfig`.

Alternately, to start the development server manually, you can run the following

```shell
❯ litestar assets serve
Using Litestar app from app:app
Starting Vite build process ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

> build
> vite build


vite v5.0.7 building for production...

✓ 0 modules transformed.

```

**Note** This is equivalent to the the `npm run dev` command when `hot_reload` is enabled. Otherwise it is equivalent to `npm run build -- --watch`. This command is configurable.

### Building for Production

```shell
❯ litestar assets build
Using Litestar app from app:app
Starting Vite build process ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

> build
> vite build


vite v5.0.7 building for production...

✓ 0 modules transformed.

```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "litestar-vite",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "litestar, vite",
    "author": null,
    "author_email": "Cody Fincher <cody.fincher@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/c7/b5/b1225f53804a577507fedf05f79859ebf94edf07d3c32979e952bc26c228/litestar_vite-0.11.1.tar.gz",
    "platform": null,
    "description": "# Litestar Vite\n\n## Installation\n\n```shell\npip install litestar-vite\n```\n\n## Usage\n\nHere is a basic application that demonstrates how to use the plugin.\n\n```python\nfrom __future__ import annotations\n\nfrom pathlib import Path\n\nfrom litestar import Controller, get, Litestar\nfrom litestar.response import Template\nfrom litestar.status_codes import HTTP_200_OK\nfrom litestar.template.config import TemplateConfig\nfrom litestar.contrib.jinja import JinjaTemplateEngine\nfrom litestar_vite import ViteConfig, VitePlugin\n\nclass WebController(Controller):\n\n    opt = {\"exclude_from_auth\": True}\n    include_in_schema = False\n\n    @get([\"/\", \"/{path:str}\"],status_code=HTTP_200_OK)\n    async def index(self) -> Template:\n        return Template(template_name=\"index.html.j2\")\n\ntemplate_config = TemplateConfig(engine=JinjaTemplateEngine(directory='templates/'))\nvite = VitePlugin(config=ViteConfig())\napp = Litestar(plugins=[vite], template_config=template_config, route_handlers=[WebController])\n\n```\n\nCreate a template to serve the application in `./templates/index.html.h2`:\n\n```html\n<!DOCTYPE html>\n<html>\n  <head>\n    <meta charset=\"utf-8\" />\n    <!--IE compatibility-->\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n    <meta\n      name=\"viewport\"\n      content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0\"\n    />\n  </head>\n\n  <body>\n    <div id=\"app\"></div>\n    {{ vite_hmr() }} {{ vite('resources/main.ts') }}\n  </body>\n</html>\n```\n\n### Template initialization (Optional)\n\nThis is a command to help initialize Vite for your project. This is generally only needed a single time. You may also manually configure Vite and skip this step.\n\nto initialize a Vite configuration:\n\n```shell\n\u276f litestar assets init\nUsing Litestar app from app:app\nInitializing Vite \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nDo you intend to use Litestar with any SSR framework? [y/n]: n\nINFO - 2023-12-11 12:33:41,455 - root - commands - Writing vite.config.ts\nINFO - 2023-12-11 12:33:41,456 - root - commands - Writing package.json\nINFO - 2023-12-11 12:33:41,456 - root - commands - Writing tsconfig.json\n```\n\n### Install Javascript/Typescript Packages\n\nInstall the packages required for development:\n\n**Note** This is equivalent to the the `npm install` by default. This command is configurable.\n\n```shell\n\u276f litestar assets install\nUsing Litestar app from app:app\nStarting Vite package installation process \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nadded 25 packages, and audited 26 packages in 1s\n\n\n5 packages are looking for funding\n  run `npm fund` for details\n\n\nfound 0 vulnerabilities\n```\n\n### Development\n\nTo automatically start and stop the Vite instance with the Litestar application, you can enable the `use_server_lifespan` hooks in the `ViteConfig`.\n\nAlternately, to start the development server manually, you can run the following\n\n```shell\n\u276f litestar assets serve\nUsing Litestar app from app:app\nStarting Vite build process \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n> build\n> vite build\n\n\nvite v5.0.7 building for production...\n\n\u2713 0 modules transformed.\n\n```\n\n**Note** This is equivalent to the the `npm run dev` command when `hot_reload` is enabled. Otherwise it is equivalent to `npm run build -- --watch`. This command is configurable.\n\n### Building for Production\n\n```shell\n\u276f litestar assets build\nUsing Litestar app from app:app\nStarting Vite build process \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n> build\n> vite build\n\n\nvite v5.0.7 building for production...\n\n\u2713 0 modules transformed.\n\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Vite plugin for Litestar",
    "version": "0.11.1",
    "project_urls": {
        "Changelog": "https://cofin.github.io/litestar-vite/latest/changelog",
        "Discord": "https://discord.gg/X3FJqy8d2j",
        "Documentation": "https://cofin.github.io/litestar-vite/latest/",
        "Homepage": "https://cofin.github.io/litestar-vite/latest/",
        "Issue": "https://github.com/cofin/litestar-vite/issues/",
        "Source": "https://github.com/cofin/litestar-vite"
    },
    "split_keywords": [
        "litestar",
        " vite"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d4fba9f929aeacdd36fcea44fe5e2e42de7a9d2266c27f01bfe4dd28be5e63bf",
                "md5": "23aaae8e2001b796e61b0539a924b956",
                "sha256": "5f63f4f1fca54187f5c5c1c1144ef3b751eaee55c1408417aac8d2aa269026a1"
            },
            "downloads": -1,
            "filename": "litestar_vite-0.11.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "23aaae8e2001b796e61b0539a924b956",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 31138,
            "upload_time": "2024-12-09T03:01:03",
            "upload_time_iso_8601": "2024-12-09T03:01:03.846687Z",
            "url": "https://files.pythonhosted.org/packages/d4/fb/a9f929aeacdd36fcea44fe5e2e42de7a9d2266c27f01bfe4dd28be5e63bf/litestar_vite-0.11.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c7b5b1225f53804a577507fedf05f79859ebf94edf07d3c32979e952bc26c228",
                "md5": "780a4ecba6904c2ecc3144f24c2e6b98",
                "sha256": "ffd5fb83d0e9c339b8fb42ad143ed862486045c38dd6a0e23fa3ec3a80dc34a7"
            },
            "downloads": -1,
            "filename": "litestar_vite-0.11.1.tar.gz",
            "has_sig": false,
            "md5_digest": "780a4ecba6904c2ecc3144f24c2e6b98",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 48378,
            "upload_time": "2024-12-09T03:01:05",
            "upload_time_iso_8601": "2024-12-09T03:01:05.767428Z",
            "url": "https://files.pythonhosted.org/packages/c7/b5/b1225f53804a577507fedf05f79859ebf94edf07d3c32979e952bc26c228/litestar_vite-0.11.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-09 03:01:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cofin",
    "github_project": "litestar-vite",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "litestar-vite"
}
        
Elapsed time: 4.52740s