This repository is a bootstrap exemple for a project with multiple apps :
- api (NestJS)
- web (NextJS)
Using pnpm workspaces (and turborepo for conveniance)
apps => application that can be started
packages => shared packages
Every package or app must have a package.json file describing dependencies, naming of the package should be @my-project/package-name (change my-project by what you want but keep consistency).
- Install the IDE extension Biome (for linting)
- Install pnpm (from website curl, if you want pnpm to automaticaly manage node version, which is recommended, avoid npm, corepack or packaga manager => https://pnpm.io/installation)
- Install dependencies:
pnpm i
For linting, you can replace biome with packages/eslint you will find an exemple in the legacy git branch.
pnpm dev
all apps will be launched in parallel.
pnpm build
pnpm test
or
pnpm test:watch
pnpm lint
or to fix issues:
pnpm lint:fix
Turborepo is used to run scripts in parallel and cache results.
It is fundamentaly not a requirement since pnpm run -R can also do that.
The challenge of a monorepo is to make packages shareable, usualy we do that by compiling packages prior to using them within the apps.
It may cause issues with live-reloads, since the dependency packages will need to be recompiled first when a package is updated, and the apps will need to know that and rebuild too. Also if one app is ESM and the other is CommonJS, it will cause issues, and will need a "double" compilation of the package. Precompiling package also means dependency can have trouble being tree-shaken.
The approach here is to use :
- webpack on NestJS, compiling everything and using
node-externalsfor exclusions (like node_modules) except for the packages starting by our prefix@my-project - transpilePackages on NextJS, to compile the packages starting by our prefix
@my-project
This way, the apps themselves use the package sources directly without the need to be precompiled first.
Biome is used for linting and formatting. Faster than eslint, but less available rules, also handle formatting (instead of prettier).