litestar-vite


Namelitestar-vite JSON
Version 0.1.22 PyPI version JSON
download
home_pageNone
SummaryVite plugin for Litestar
upload_time2024-03-23 21:31:26
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

> [!IMPORTANT]
> This plugin currently contains minimal features and is a work-in-progress

## 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_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")


vite = VitePlugin(
    config=ViteConfig(
        bundle_dir=Path("./public"),
        resource_dir=Path("./resources"),
        template_dir=Path("./templates"),
        # Should be False when in production
        dev_mode=True,
        hot_reload=True, # Websocket HMR asset reloading is enabled when true.
    ),
)
app = Litestar(plugins=[vite], 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/7d/6d/1228342db2c4f47946c4f5c660463580d157656be98e7782c9834d6cabaf/litestar_vite-0.1.22.tar.gz",
    "platform": null,
    "description": "# Litestar Vite\n\n> [!IMPORTANT]\n> This plugin currently contains minimal features and is a work-in-progress\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_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\n\nvite = VitePlugin(\n    config=ViteConfig(\n        bundle_dir=Path(\"./public\"),\n        resource_dir=Path(\"./resources\"),\n        template_dir=Path(\"./templates\"),\n        # Should be False when in production\n        dev_mode=True,\n        hot_reload=True, # Websocket HMR asset reloading is enabled when true.\n    ),\n)\napp = Litestar(plugins=[vite], route_handlers=[WebController])\n\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.1.22",
    "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": "cbb514733625f5b4ecf95708beadc34d13b0eabeb9009f31e0fffd7bc423f140",
                "md5": "90ccedf7a71b63a227a7745019aa527a",
                "sha256": "d950a665d6c261c6ecb2b2be129077abca43e8e464f1a39fc74cad6cd70816ab"
            },
            "downloads": -1,
            "filename": "litestar_vite-0.1.22-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "90ccedf7a71b63a227a7745019aa527a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18701,
            "upload_time": "2024-03-23T21:31:24",
            "upload_time_iso_8601": "2024-03-23T21:31:24.964785Z",
            "url": "https://files.pythonhosted.org/packages/cb/b5/14733625f5b4ecf95708beadc34d13b0eabeb9009f31e0fffd7bc423f140/litestar_vite-0.1.22-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7d6d1228342db2c4f47946c4f5c660463580d157656be98e7782c9834d6cabaf",
                "md5": "804fb4df9e99bef02863df8c5ca0ef9a",
                "sha256": "7062a7b1ed25f60476dde0eb81ec076d14c958b4eff226f33c77b25f60929c70"
            },
            "downloads": -1,
            "filename": "litestar_vite-0.1.22.tar.gz",
            "has_sig": false,
            "md5_digest": "804fb4df9e99bef02863df8c5ca0ef9a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 79663,
            "upload_time": "2024-03-23T21:31:26",
            "upload_time_iso_8601": "2024-03-23T21:31:26.782819Z",
            "url": "https://files.pythonhosted.org/packages/7d/6d/1228342db2c4f47946c4f5c660463580d157656be98e7782c9834d6cabaf/litestar_vite-0.1.22.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-23 21:31:26",
    "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: 0.24794s