Reference
newt add app
Adds a React app to a context, served by the backend at /<context>.
newt add app gives a context its app, served by the same backend at /<context>, such as /tasks. It writes a small React app that Bun bundles, or serves one you build elsewhere.
newt add app <context> [options]Arguments
Section titled “Arguments”| Argument | Meaning |
|---|---|
context |
A context of the backend, as in tasks |
Options
Section titled “Options”| Option | Default | Meaning |
|---|---|---|
--built <folder> |
none | Serve an app built elsewhere, from the folder of its index.html |
--backend <folder> |
the one you are in | The backend, in a monorepo with several |
It also takes the global flags.
- Without
--built, newt writes a React app insrc/contexts/<context>/app/. - With
--built, the folder must be built for/<context>/, as invite build --base=/<context>/. Its path is relative to where you run the command.
What it writes
Section titled “What it writes”newt add app tasks created src/contexts/tasks/app/index.html created src/contexts/tasks/app/main.tsx created src/contexts/tasks/app/app.tsx created src/contexts/tasks/app/base.ts created src/contexts/tasks/app/tsconfig.json updated package.json updated tsconfig.json updated src/contexts/tasks/tasks.context.ts updated src/backend.test.ts
Next steps: bun install bun run dev, and open /tasksimport { default as app } from './app/index.html'// … const context = Tasks_Context.initialize(base, router) return { context, router, host, app }app/base.tsholds where the app is served,BASE, and its API,API.app/tsconfig.jsontakes the context’s schemas, their value objects and errors too, so the app type-checks the DTOs it imports.package.jsongetsreactandreact-dom, with@types/reactand@types/react-domas devDependencies.tsconfig.jsonleaves the app folders out and references the app’s owntsconfig.json.src/backend.test.tsgets a test that the app’s page is served.- With
--built web/dist, onlytasks.context.tsandsrc/backend.test.tschange: the context handsapp: join(import.meta.dir, '../../../web/dist'), and the test runs once the folder has anindex.html.
Warnings
Section titled “Warnings”- With
--built, a folder withoutindex.htmlyet: the backend answers 503 at/<context>until it is built.
Next steps
Section titled “Next steps”Without --built:
bun installbun run dev, and open/<context>
With --built: build it into the folder for /<context>/, or its assets answer 404. Then bun run dev and open /<context>/.
Errors
Section titled “Errors”- Missing context:
newt add app takes the context, as in newt add app sales. - A context the backend does not have: refused; add it with
newt add context. - The context hands an app already, in
<context>.context.ts: refused; take that one out first. - A
--builtfolder that holds the backend: refused, since everything in it would be served,.envtoo.
See Adding an app.