|
| 1 | +--- |
| 2 | +outline: deep |
| 3 | +--- |
| 4 | + |
| 5 | +# Assets |
| 6 | + |
| 7 | +Browse, preview, upload, rename, and delete the files in a directory, built as a **Vue** SPA on `@antfu/design` — a framework-neutral port of Nuxt DevTools' Assets tab. |
| 8 | + |
| 9 | +Package: `@devframes/plugin-assets` · framework: **Vue + @antfu/design** |
| 10 | + |
| 11 | +## What it does |
| 12 | + |
| 13 | +Search by name and filter by type from an inline chip row, switch between a thumbnail grid (grouped by folder) and a file tree, and open a resizable right-hand details panel with a live preview (image, video, audio, font, or text), file metadata, and ready-to-copy usage snippets (`<img>`, CSS `background-image`, `@font-face`, a download link). Upload files with the toolbar button (native file picker) or by dropping them anywhere on the frame, and select multiple assets to delete them together. A live file watcher keeps every connected client's listing in sync with changes made outside the UI. |
| 14 | + |
| 15 | +The standalone server requires devframe's trust handshake by default because it can read, write, and delete real files. Uploads, renames, deletes, and folder creation are enabled by default — pass `{ write: false }` (or `--read-only` on the standalone CLI) for a browse-only deployment. |
| 16 | + |
| 17 | +## Standalone |
| 18 | + |
| 19 | +```sh |
| 20 | +pnpx @devframes/plugin-assets # manages <cwd>/public |
| 21 | +pnpx @devframes/plugin-assets --read-only # disable upload / rename / delete / mkdir |
| 22 | +``` |
| 23 | + |
| 24 | +## Mount into a Vite host |
| 25 | + |
| 26 | +```ts |
| 27 | +// vite.config.ts |
| 28 | +import { assetsVitePlugin } from '@devframes/plugin-assets/vite' |
| 29 | +import { defineConfig } from 'vite' |
| 30 | + |
| 31 | +export default defineConfig({ |
| 32 | + plugins: [ |
| 33 | + assetsVitePlugin(), |
| 34 | + ], |
| 35 | +}) |
| 36 | +``` |
| 37 | + |
| 38 | +## Programmatic |
| 39 | + |
| 40 | +`createAssetsDevframe(options)` returns a definition you can deploy through any adapter: |
| 41 | + |
| 42 | +```ts |
| 43 | +import { createAssetsDevframe } from '@devframes/plugin-assets' |
| 44 | + |
| 45 | +export default createAssetsDevframe({ |
| 46 | + dir: 'static', // defaults to `<cwd>/public` |
| 47 | + baseURL: '/', // the URL the host serves `dir` at |
| 48 | + write: true, |
| 49 | + uploadExtensions: ['png', 'jpg', 'svg', 'webp'], // defaults to Nuxt DevTools' own allow-list, or '*' for any |
| 50 | +}) |
| 51 | +``` |
| 52 | + |
| 53 | +| Option | Default | Description | |
| 54 | +|--------|---------|-------------| |
| 55 | +| `dir` | `<cwd>/public` | Directory this devframe manages. | |
| 56 | +| `baseURL` | `/` | URL base the host serves `dir` at — each asset's `publicPath` is `baseURL` + its path. Match a non-root deployment base (e.g. Nuxt's `app.baseURL`). | |
| 57 | +| `write` | `true` | Enable upload, rename, delete, and folder creation from the UI. | |
| 58 | +| `uploadExtensions` | Nuxt DevTools' allow-list | Extensions `upload` accepts, or `'*'` for any. | |
| 59 | +| `serveStatic` | `false` | Serve the directory's bytes from this devframe itself. Left off when mounted into a host that already serves `public/`; the standalone CLI turns it on. | |
| 60 | +| `build` | `false` | Register the `build` CLI subcommand. See [why it's off by default](#static-export) below. | |
| 61 | + |
| 62 | +## How previews are served |
| 63 | + |
| 64 | +Asset previews (`<img>`, `<video>`, download links) load the files by their **public URL**, and the host the plugin is mounted into serves those files — Vite, Nuxt, and most frameworks already serve their `public/` folder at `/`. The plugin never stands up its own byte-serving route; it just resolves each asset's `publicPath` as `baseURL` + the file's path. Point `baseURL` at wherever the host serves `dir` (the default `/` matches the usual `public/` convention). The standalone CLI (`pnpx @devframes/plugin-assets`) is its own host, so it flips `serveStatic` on and serves the directory under a dedicated base. |
| 65 | + |
| 66 | +## RPC surface |
| 67 | + |
| 68 | +All functions are namespaced `devframes:plugin:assets:*`: |
| 69 | + |
| 70 | +| Function | Type | Notes | |
| 71 | +|----------|------|-------| |
| 72 | +| `list` | `query`, `snapshot: true` | Every file under the managed directory, with type, size, and last-modified time. | |
| 73 | +| `capabilities` | `query`, `snapshot: true` | Whether write actions are enabled, and the upload allow-list — lets the UI gate itself proactively. | |
| 74 | +| `read-image-meta` | `query` | Width, height, and orientation for an image asset. | |
| 75 | +| `read-text` | `query` | Truncated text content, for preview. | |
| 76 | +| `upload` | `action` | Allocates a streaming upload slot; the client pipes the file's bytes over the paired channel. | |
| 77 | +| `rename` | `action` | Renames an asset within its folder, preserving its extension. | |
| 78 | +| `delete` | `action` | Deletes one or more assets in a single call. | |
| 79 | +| `mkdir` | `action` | Creates a folder, including missing parents. | |
| 80 | +| `open-in-editor` / `reveal-in-folder` | `action` | Launch the asset in your editor, or reveal its containing folder in the OS file manager. Always registered, regardless of `write`. | |
| 81 | + |
| 82 | +`upload` / `rename` / `delete` / `mkdir` are registered only when `write` is enabled. |
| 83 | + |
| 84 | +## Static export |
| 85 | + |
| 86 | +Every devframe's `build` CLI subcommand is disabled here by default (`capabilities: { build: false }`). A static export has no live host serving the files, and every write action is inherently excluded from a static dump. Rather than ship a broken, preview-less, write-less shell of the tool, the `build` command is simply not registered. Pass `{ build: true }` to `createAssetsDevframe()` (and `{ force: true }` if calling `createBuild()` directly) if that degraded export is still useful to you — the file listing itself still bakes into the static RPC dump. |
| 87 | + |
| 88 | +## Source |
| 89 | + |
| 90 | +[`plugins/assets`](https://github.com/devframes/devframe/tree/main/plugins/assets) |
0 commit comments