Deploy your app

2 min·Assumes: routes are files

One build turns your app into an output folder, and a
decides which host that folder is shaped for.
import { markless } from '@markless/core/vite';
import { router } from '@markless/router/vite';
import { defineConfig } from 'vite-plus';

export default defineConfig({
	plugins: [markless(), router()],
});

router() builds your pages, endpoints and middleware into a server. markless() compiles each .tsrx file on the way.

The same code builds for any host

The router builds on Nitro, and a preset names the host the output is for. Flip the preset, then try to drag a file into the output.

$ npm run buildNITRO_PRESET=node-serverNITRO_PRESET=vercelNITRO_PRESET=cloudflare-moduleNodeVercelCloudflare.output/server/index.mjspublic/build/.vercel/output/functions/__server.func/static/config.json.output/server/index.mjswrangler.jsonpublic/_headersmy-app/pages/index.tsrxabout.tsrxdocument.tsrxvite.config.ts
Three inked cards on a desk. On the left, your app's source: a my-app folder with pages, index.tsrx, about.tsrx, document.tsrx and vite.config.ts, with a small padlock. In the middle, a terminal running npm run build, with three keys above it: Node, Vercel and Cloudflare. On the right, the folder the build wrote. Press a key, or use the arrow keys on it, and the terminal runs again and the output folder redraws: .output with server/index.mjs and public/build for Node; .vercel/output with functions/__server.func, static and config.json for Vercel; .output with server/index.mjs, server/wrangler.json, public and public/_headers for Cloudflare. The source never changes. Hover or focus an output file to see what the host does with it. Drag a source file into the output and it slides back.

  • Node is the default, and needs no preset.
  • NITRO_PRESET=vercel writes .vercel/output/.
  • NITRO_PRESET=cloudflare-module writes a Worker into .output/.
NITRO_PRESET=vercel npm run build

These three are tested with Markless. Treat Nitro's other presets as untested, and try a preview deploy first.

Node runs the server you built

npm run build
PORT=3000 node .output/server/index.mjs

The server reads its port from PORT. Run npm run preview to try the build first. The starter's .gitignore already leaves .output/ out of git.

Prerendered pages are free on Cloudflare

Deploy with npx wrangler deploy --config .output/server/wrangler.json. Cloudflare serves files in .output/public/ without running your Worker:

  • Give a page prerender: true in its route rule, and give its /_markless/fragment/... path the same rule.
  • Pages that aren't prerendered render in the Worker and stream, so @pending content still shows first.
  • Name the Worker with name in a wrangler.json next to vite.config.ts.

Memory isn't shared between servers

A host runs many copies of your server, called instances, and each has its own memory. Put sessions and carts in a database or a key-value store. For one copy per instance, such as a database pool, put it on globalThis:

const pool = (globalThis.dbPool ??= createPool(process.env.DATABASE_URL));
Nitro settings in vite.config.ts

Put Nitro settings under a top-level nitro key, and the router merges them in. This app serves from a sub-path:

import { markless } from '@markless/core/vite';
import { router } from '@markless/router/vite';
import { defineConfig } from 'vite-plus';

export default defineConfig({
	base: '/shop/',
	nitro: { baseURL: '/shop/' },
	plugins: [markless(), router()],
});

Don't add nitro() to plugins yourself; the build stops and asks you to remove it.

Back to the start of this section: make a file, get a URL.