Skip to content

Node.js package-based monorepo template, based on Nx.

Notifications You must be signed in to change notification settings

dormeiri/nodejs-package-based-monorepo-template

Repository files navigation

Package Based Monorepo Template

Setup

npm ci

Commands

Common

npx nx lint <project name>
npx nx test <project name>
npx nx build <project name>

Read more about running tasks with Nx

Generating a new package

npm run generate:package <project name>

Testing packages locally

With link

In the package dist folder run npm link

And then in your consumer run npm link @%template%@<project>

Run npm unlink in the package dist folder to remove the link.

Run nx build <project> to take changes you make into the consumer.

With local registry

We are using verdaccio for the local registry.

We have some commands to make it even more easy:

npm run local-registry help

See more in local-registry.mjs

Publish locally

npm run local-registry publish <project name>

By default, the version is 0.0.0-local.1 with the tag local and the registry is http://localhost:4873, you can explore more in publish.mjs and local-registry.mjs

In local environment, the version is being overwritten if it is already exist.

Installing a local package

npm:

npm install @%template%/<package name>@local --registry=http://localhost:4873

yarn:

yarn add @%template%/<package name>@local --registry=http://localhost:4873

Using the template

Search and replace

  1. Search and replace @%template% scopes to another.
  2. Search and replace https://registry.npmjs.org registry to yours.

Integrate with CI/CD

CI

You can check your changes with Nx tasks, for example you can run:

npx nx affected --target=lint --base=origin/master
npx nx affected --target=test --base=origin/master
npx nx affected --target=build --base=origin/master

CD

One way of determine which package should be deployed is by using git tags with the format <project name>/<version>. Then, your can run in your CD npx nx publish $project_name --args="--ver=$version --env=production".