GitHub 37
Skip to content
ViteHub is still experimental. Expect bugs and breaking changes.

Workspace

A folder of files your server can read and write, with rules for each path and a record of every change.

server/workspaces/docs.ts
import { defineWorkspace, glob } from 'vite-hub/workspace'

// This file defines the docs Workspace.
export default defineWorkspace({
  sources: {
    // Markdown from your docs folder
    docs: glob({ cwd: 'docs', include: '**/*.md' }),
  },
  rules: {
    // Your files stay read-only
    'docs/**': { write: false },
  },
})
server/workspaces/docs.ts

One file defines it

Add a file to server/workspaces. The file name is the Workspace name.

Start from files you have

Show files from your project or GitHub. The originals stay unchanged.

Read and write from a route

Use readFile(), writeFile(), and glob() from useWorkspace().

Decide who can write where

Make a path read-only or limit its file types.

See every change

diff() lists changes. A snapshot saves a version to read later.

Same code in development and production

Files stay on disk in dev, and your routes stay the same when you deploy.