Metadata-Version: 2.4
Name: nyxa-assets
Version: 0.0.1
Summary: Vite asset pipeline for Nyxa — dev proxy, manifest resolution, vite() helper
Author-email: Al-Amin Islam Nerob <alamin@aincoder.com>
License-Expression: MIT
Project-URL: Repository, https://github.com/NyxaDev/Nyxa
Requires-Python: >=3.13
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: nyxa>=0.0.1
Dynamic: license-file

# nyxa-assets

Vite asset pipeline for Nyxa — dev-server proxying with HMR, manifest
resolution for production builds, a `vite()`/`@vite` tag helper, and a
`nyxa build` hook that runs the frontend build.

## Features

- **`AssetsManager` (`app.assets`)** — `assets.resolve(entry)`
  returns the asset URL: `<dev_server>/<entry>` in dev, the
  fingerprinted file from the Vite manifest in production (missing
  entries raise `LookupError` — fail closed, no silent 404s).
- **`vite()`/`@vite` helper** — emits `<script type="module">` and
  `<link rel="stylesheet">` tags for entries; injects the Vite HMR
  client in dev. Registered into `nyxa-view` automatically when both
  are installed (`@vite("resources/app.ts")`).
- **Dev proxy** — `AssetsProxyMiddleware` forwards `/_vite/*` to the
  configured dev server while `assets.dev` (debug on,
  `NYXA_ASSETS_PROD` unset); production never proxies.
- **Dev detection** — `assets.dev` = `app.debug` and
  `NYXA_ASSETS_PROD != "1"` (set the env var to test manifest mode in
  debug).
- **CDN support** — `assets.url` prefixes resolved URLs for external
  hosts; empty serves from `/build`.
- **`nyxa build` hook** — runs `npm run build` when the app has a
  `package.json` (warns, never fails the build).
- **Starter kit** — `web_kit` scaffolds a Vite + forms + views demo
  app via `nyxa add`.
- **Telemetry** — emits `assets.manifest` (hit/miss) per lookup.

## Install

```bash
nyxa add nyxa-assets   # writes config/assets.py
```

## Usage

```python
# in a template (nyxa-view):
#   @vite("resources/app.css")
#   @vite("resources/app.ts")

# or directly:
tags = app.assets.vite("resources/app.css", "resources/app.ts")
url = app.assets.resolve("resources/app.ts")
```

## Public API

- **`AssetsManager`** — bound as `app.assets`:
  `manager.dev -> bool`, `manager.manifest() -> dict`,
  `manager.resolve(entry) -> str`, `manager.vite(*entries) -> str`
  (HTML tags); config mirrors: `build_dir`, `manifest_name`, `url`,
  `dev_server`.
- **`AssetsProxyMiddleware`** — proxies `/_vite/*` to the dev server
  in assets-dev mode: `AssetsProxyMiddleware(prefix="/_vite")`;
  installed globally by the provider.
- **`AssetsProvider`** — binds `app.assets`, installs the proxy,
  registers the `vite` view helper, contributes the `npm run build`
  `nyxa build` hook, and writes `config/assets.py` on `nyxa add`.

## Configuration

`nyxa add nyxa-assets` writes `config/assets.py`:

```python
config = {
    "build_dir": "build/assets",
    "manifest": "manifest.json",
    "url": "",  # CDN prefix ("" → /build)
    "dev_server": "http://localhost:5173",
}
```

`NYXA_ASSETS_PROD=1` forces manifest mode even under `debug=True`.

## License

MIT
