Deploy your app
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.
- Node is the default, and needs no preset.
NITRO_PRESET=vercelwrites.vercel/output/.NITRO_PRESET=cloudflare-modulewrites a Worker into.output/.
NITRO_PRESET=vercel npm run buildThese 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.mjsThe 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: truein its route rule, and give its/_markless/fragment/...path the same rule. - Pages that aren't prerendered render in the Worker and stream, so
@pendingcontent still shows first. - Name the Worker with
namein awrangler.jsonnext tovite.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.