Node.js Monorepo example with npm Workspaces
Monorepo structure of TypeScript and NestJS project using Lerna and npm Workspaces
- Not using NestJS monorepo mode.
- Lerna now depends on Nx, so you can use Nx commands while using Lerna.
npm ci
npm run lint
npm run test
npm run build
# The above command can also be used like this:
npx lerna run lint,test,build
#= npx nx run-many --target=build
# Run tasks affected
npx lerna run build --since=main
#= npx nx affected --target=build
# package manage to a specific workspace
npm i -w sample-nestjs-app install-package
npm uninstall -w sample-nestjs-app uninstall-package
npm ci -w sample-nestjs-app
# launch the development process
npx lerna run dev --scope=sample-nestjs-app
#= npx nx run sample-nestjs-app:dev
# execute npm tasks
npx lerna run any-task --scope=workspace-name
npx lerna exec npm run any-task --scope=workspace-name
#= npx nx run workspace-name:any-task
npm run any-task -w workspace-name
# https://docs.npmjs.com/cli/v9/commands/npm-ci#omit
npm ci -w sample-nestjs-app --omit=dev
- See https://docs.npmjs.com/cli/v9/commands/npm-init#workspaces-support
- Modify workspace by refer to the sample code. or edit after copy-paste
npm init -w apps/app-name
npm init -w packages/package-name
- Modify the pah mapping in tsconfig.json.
+-- apps
| +-- sample-app // TypeScript simple sample-app
| +-- sample-nestjs-app // NestJS server sample-app
+-- packages
| +-- sample-lib // TypeScript simple sample-package
| +-- sample-nestjs-lib // NestJS module sample-package
+-- .eslintrc // ESLint common configuration
+-- jest.config.ts // Jest common configuration
+-- lerna.json // Lerna configuration
+-- nx.json // Nx task pipeline configuration