Skip to Content
Vuesho

Deploying

Deploy to a static host or a server.

vuesho build builds the site for a static host or for a server. A site needs a server only when something renders on request, like the pages of a dynamic source or the AI chat.

Building the Site

npm run build

By default, the build writes the pages and assets to .output/public, and the server to .output/server. To check the build before you deploy it, serve it locally:

npm run preview

Static Hosting

For a static host, set Nitro's static option in vite.config.ts:

vite.config.ts
import { defineConfig } from "vite";
import vuesho from "vuesho/vite";

export default defineConfig({
  plugins: [vuesho()],
  nitro: { static: true }, 
});

The build then writes only static files, to .output/public by default, which any static host serves. A dynamic source is read once, when the site builds. When something else needs a server, the build names it in an error or a warning.

GitHub Pages

  1. Set the github-pages preset, which is static. For a project site, like https://acme.github.io/docs/, also set the base path:

    vite.config.ts
    import { defineConfig } from "vite";
    import vuesho from "vuesho/vite";
    
    export default defineConfig({
      base: "/docs/",
      plugins: [vuesho()],
      nitro: { preset: "github-pages" },
    });
  2. Add a workflow:

    .github/workflows/deploy.yml
    name: Deploy
    on:
      push:
        branches: [main]
    
    permissions:
      contents: read
      pages: write
      id-token: write
    
    jobs:
      deploy:
        runs-on: ubuntu-latest
        environment:
          name: github-pages
          url: ${{ steps.deployment.outputs.page_url }}
        steps:
          - uses: actions/checkout@v5
            with:
              fetch-depth: 0 # Full Git history, for the page dates
          - uses: actions/setup-node@v5
            with:
              node-version: 24
              cache: npm
          - run: npm ci
          - run: npm run build # `npm run docs:build` for a site in `docs/`
          - uses: actions/upload-pages-artifact@v4
            with:
              path: .output/public # `docs/.output/public` for a site in `docs/`
          - id: deployment
            uses: actions/deploy-pages@v4
  3. In the repository settings, under Pages, set the source to GitHub Actions.

Trailing Slashes

A static build writes the page /guide to guide.html. For a host that serves only the index.html of a folder, like nginx by default, end the URLs with a slash, so the build writes guide/index.html:

vite.config.ts
export default defineConfig({
  plugins: [vuesho({ trailingSlash: true })],
});

Server Hosting

Without static: true, the build includes a Nitro server. Nitro detects Vercel, Netlify and Cloudflare when the site builds on them. Elsewhere, set the preset in vite.config.ts, like nitro: { preset: "vercel" }.

The default preset, node-server, builds a server that runs from .output:

node .output/server/index.mjs

The server listens on PORT, 3000 by default, and HOST. Build on the same operating system and CPU architecture as the server, since native packages, like the renderer of Open Graph images, are installed for the machine that builds.

Error Monitoring

When a page fails to render on the server, the server logs the error and responds with the theme's ServerError page and the status 500. To report the error to a monitoring service, add a Nitro plugin:

import { definePlugin } from "nitro";

export default definePlugin((nitroApp) => {
  nitroApp.hooks.hook("error", (error, { event }) => {
    // Report `error`, with `event?.req.url`
  });
});

Base Path

For a site under a path, like https://acme.dev/docs/, set base in vite.config.ts:

vite.config.ts
export default defineConfig({
  base: "/docs/", 
  plugins: [vuesho()],
});

Write links, images, plugin routes and the head tags of the config without the base path, and Vuesho adds it. In a Vue component, use Link or addBasePath() from vuesho/client. site.baseUrl stays the origin, https://acme.dev.

Redirects and Headers

Nitro's route rules in vite.config.ts redirect moved pages and set response headers:

vite.config.ts
export default defineConfig({
  plugins: [vuesho()],
  nitro: {
    routeRules: {
      "/old-guide": { redirect: { to: "/guide", status: 308 } },
      "/v1/**": { redirect: "/v2/**" },
      "/api/**": { headers: { "cache-control": "no-store" } },
    },
  },
});

A redirect responds with 307 unless it sets status. With a base path, write a rule's path without it, and the target of a redirect with it, like /docs/guide.

A static build keeps the rules that its host applies: Vercel applies all of them, Netlify and Cloudflare Pages all but proxy, and a Cloudflare Worker only headers and cors. Where the host applies no redirects, the build writes a redirect of an exact path as a page that redirects. The build warns about each rule it can't keep, which you then set in the host's config.

Environment Variables

vuesho.config.ts and plugins read variables from process.env. vuesho dev and vuesho build load them from these files, as Vite does:

.env                # every mode
.env.local          # every mode
.env.[mode]         # only in that mode
.env.[mode].local   # only in that mode

A deployed server reads no .env file, so set the variables on the host. Pages rendered at build time keep the values of the build, while pages and routes rendered on request get the values of the server's host.

Public Variables

A variable that starts with VITE_ reaches the browser through import.meta.env. Never give a secret that prefix.

Assets on a CDN

To serve the hashed files of the build from another origin, use Vite's renderBuiltUrl:

vite.config.ts
export default defineConfig({
  plugins: [vuesho()],
  experimental: {
    renderBuiltUrl: (file, { type }) =>
      type === "asset" ? `https://cdn.acme.dev/${file}` : undefined,
  },
});

Upload .output/public/assets/ and .output/public/_vuesho/m/ to the same paths on the CDN, and allow CORS. On a site with pages rendered on request, return undefined for .js files, so the scripts stay on the site's origin.

Content Security Policy

Each page has a small inline script that applies the color mode before the page renders. A strict policy allows it by its hash, colorModeScriptHash from vuesho/config:

vite.config.ts
import { defineConfig } from "vite";
import { colorModeScriptHash } from "vuesho/config"; 
import vuesho from "vuesho/vite";

export default defineConfig({
  plugins: [vuesho()],
  nitro: {
    routeRules: {
      "/**": {
        headers: { "content-security-policy": `script-src 'self' ${colorModeScriptHash}` },
      },
    },
  },
});

On another static host, set the header in the host's config, as Redirects and Headers describes. A page rendered on request can use a nonce instead: a plugin's middleware sets the policy with the nonce on the request it passes to next(), and on the response.