arc serve
Serve the game locally.
Usage
arc serve [options]
Options:
-p, --port Serve on this port [number] [default: 4100]
--build Run the build command first [boolean] [default: true]
--url Frame another server's page instead of deploy_dir [string]
-o, --open Open the play page in a web browser [boolean] [default: false]
-q, --quiet Output only errors [boolean] [default: false]
-C, --cwd Set the working directory [string] [default: "."]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Description
Serves what arc deploy would publish, on your machine, the way Arcadible serves it: framed in a play page, with the Arcadible SDK. It runs workflow.build first, then serves deploy_dir until you press Ctrl+C.
$ arc serve
Built and serving v1.2.0 locally.
Play:
http://localhost:4100/
Game only:
http://127.0.0.1:4100/
Reloads when .arcadible-public/ changes. Press Ctrl+C to stop.
Open the Play link. The play page and the game have origins of their own, as on Arcadible: the page is localhost, and the game 127.0.0.1. When a file in deploy_dir changes, the game reloads in the page, and the page keeps its saves.
--no-buildservesdeploy_diras it is. Run your build tool's watch mode beside it, such asvite build --watch, and each rebuild reloads the game.--portpicks another port, such as to serve two games at once (port_in_use).--urlframes another server's page, such as your engine's dev server, instead of servingdeploy_dir. See Framing a dev server.--openopens the play page in your browser.
It doesn't validate the project; run arc validate for that.
Framing a dev server
With --url, the local play page frames another server's page, so a dev server's own reloading runs inside it, with the SDK's host and the sandbox. Nothing is built or watched, since that server does both:
npm run dev # Vite, at http://localhost:5173
arc serve --url http://localhost:5173 # in another terminal
The play page is cross-origin isolated, as on Arcadible, so the page it frames must send these headers, or the browser won't load it, and arc serve warns:
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Resource-Policy: cross-origin
The engine starters' vite.config.js already sends them, on both npm run dev and npm run preview:
const headers = {
"Cross-Origin-Embedder-Policy": "require-corp",
"Cross-Origin-Resource-Policy": "cross-origin",
};
export default {
base: "./",
build: { chunkSizeWarningLimit: 2048, outDir: ".arcadible-public" },
preview: { headers },
server: { headers },
};
The other server is what the game runs on, so its paths and types are its own, not Arcadible's. Run arc serve without --url to check the build itself.
Like Arcadible
- The play page frames the game with the same sandbox and permissions as Arcadible's, so dialogs, pop-ups, and forms are blocked as they are for players (Runtime Limitations).
- Paths are case-sensitive, even on a disk that isn't: a request for
ship.pngdoesn't findShip.png. A path ending in/gets itsindex.html, and a folder without the/isn't found. - The game is cross-origin isolated, with Arcadible's headers, and each file has the type Arcadible gives it.
/arcadible/is Arcadible's, with the SDK's hosted script at/arcadible/sdk/v1.js. Anything else there isn't found.- Nothing is cached, unlike on Arcadible, so every reload gets your latest files.
The Arcadible SDK
The play page runs Arcadible's own host for the SDK, so saves work as on Arcadible, from the package or the hosted script:
arcadible.buildis{ version, channel: "local" }, with theversionyou're serving.- Saves are kept by the local play page, apart from Arcadible's, and carry over from one build to the next, as they do between versions. Each game's are its own, by its
id. A different port starts with none. - The SDK's files are fetched from Arcadible each time
arc servestarts, so they're the ones players get. When Arcadible can't be reached, the last copy is used, with a warning that says when it's from.
Output
It prints the links, then Reloaded at <time>. for each reload. Warnings, such as a copy of the SDK's files kept from before, go to stderr. There's no --json, since it runs until stopped.
| Code | When |
|---|---|
0 | Stopped with Ctrl+C |
1 | The project's files can't be read, the build failed, deploy_dir doesn't exist, the port is in use or isn't from 1 to 65535, or --url isn't an http or https URL |