I have an app that consists of an Express.js backend and an Angular frontend in a single repo. The project structure (leaving out unnecessary details) looks like this:
./
├─ client/
│ ├─ angular.json
│ ├─ index.html
│ ├─ main.ts
│ ├─ tsconfig.ts
│ ├─ ...
├─ server/
│ ├─ app.ts
│ ├─ ...
├─ shared/
│ ├─ ...
├─ package.json
To run this locally, I do the following:
npm build-server = tsc --project server/tsconfig.json
This command compiles the server typescript code and outputs the resulting javascript to dist/server and dist/shared.
npm build-client = cd client && ng build
This command runs Angular’s compiler and bundler and outputs bundled javascript files to dist/client. The server is configured in code to serve static files from this location.
npm run-server = node dist/server/app.js
This starts the server from the compiled server files. The working directory is the root directory.
I’m trying to figure out now how to translate this to a Vercel config that can build both the client and server files and then run the server. I see that there are deployment settings for Build Command, Output Directory, and Root Directory that I can override, but I’m not sure how I should configure them.
- How can I configure this to build both my client and server files?
- What should the Output Directory be? Does it need to contain both the server and client files, or only the server files?
- What should the Root Directory be? Is this the working directory of the server? Or the directory from which files are served? Should it be the root of my project folder?
- How do I tell Vercel how to run my server? It sounds like it automatically looks for an
app.{ts,js}file, but how do I point it to the correct location? And should I be pointing it toserver/app.tsordist/server/app.js?