Edit on val.town ↗

Migrate code

Use this as a reference, not a required sequence. Adapt the approach and code to suit the app and the user’s needs.

Read its entrypoints, imports, assets, and tests. Identify which code runs in the browser and which runs on the server. Preserve the app’s behavior and intended audience.

Use the closest template in the mapping table where it helps. Replace its demo with the app; preserve an existing good structure rather than forcing a rewrite.

Adapt the maintained source directly. Do not keep an old Val Town copy plus scripts that rewrite it into Cloudflare code. Preserve legitimate builds and generated assets. Keep files cohesive, folders understandable, and a concise README with the live URL and working run/test/deploy commands.

Val Town utility Migration
std/utils.readFile At build time, use Node file reads. At runtime, import text/JSON or read a file explicitly included in the Worker bundle using Workers’ virtual filesystem.
std/utils.listFiles, listFilesByPath Use node:fs.readdir during the build, or list bundled files at runtime. Workers cannot browse the original repository or Val Town project.
std/utils.serveFile Put public files in Static Assets. Keep private files behind authentication; never expose them through an unprotected assets route.
std/utils.readFileTranspiled, fetchTranspiledJavaScript Compile browser TypeScript/JSX with Vite or the existing build. Reference the resulting asset, not a Val Town transpilation endpoint.
std/utils.serveImmutableFile, immutableFileUrl Use build-generated asset hashes. Keep HTML references in sync; only mark URLs immutable when their content cannot change.
std/utils.hotReload Use the development server’s hot reload. Remove Val Town’s reload script from production.
std/utils.httpEndpoint, emailAddress Configure the new URL/address explicitly. Update callers, links, and callback registrations.

Workers’ filesystem is not your local disk: /bundle contains deployed modules, and /tmp is temporary. Use D1 or R2 for persistent data.

If hosting below a path such as /my-app/, configure the frontend base path, assets, API calls, and callbacks together.

Run the build and existing tests, then test the deployed app. Check nested routes, asset loads, forms/API calls, and browser console errors. Search source and built output for leftover esm.town, .val.run, and Val Town service URLs; replace operational dependencies, while preserving intentional attribution links.

Remove template demos and obsolete edit/remix controls. Document bindings and secret names, never values. Before switching users, verify the deployed app, data, and access controls.

Last updated