@fairgarden/monolith
Compose several Next.js apps into one deployable app.
Next only supports basePath for a monorepo, which is the right shape when each
app is built and deployed on its own. A self-hosted core or starter
distribution wants the opposite: one server, one build, one thing to run. This
library mounts each app's routes under a path prefix and merges their configs so
that works.
// apps/monolith/next.config.ts
import { withMonolith } from '@fairgarden/monolith'
export default withMonolith(
{},
{
id: '@fairgarden/id',
membership: '@fairgarden/membership',
}
)
id's routes are then served from /id, its assets from public/id, and its
Pages Router API from /api/id.
Start here
- Starting a repository — scaffolding a monolith or a module
- Overview — what mounting an app actually does
- Mounting — symlinks, and why
next devneeds different treatment - Routing — how rewrites, redirects and headers are merged
- What a monolith can serve — root mounts, and when apps collide
- Next versions — which versions can be mounted together
- Dependencies — what the monolith has to install
- Modules — keeping submodules up to date
- Portability — keeping an app mountable
- Functions — the API
Install
pnpm add @fairgarden/monolith
The package has three entry points:
| Import | For |
| --- | --- |
| @fairgarden/monolith | the monolith's next.config.ts, and an app's portability check |
| @fairgarden/monolith/link | an app's own components |
| @fairgarden/monolith/eslint | an app's eslint.config.mjs |
It also installs a fg-monolith command for the things that have to happen
before a build.