Creating a MonoRepo with NPM Workspaces
NPM Workspaces was introduced in NPM 7 and is a generic term that refers to the set of features in the npm CLI that provides support for managing multiple packages from your local filesystem, from within a singular top-level root package.
The first thing you need to do in order to create a monorepository is to create a root package.json
file, which should contain the following code:
{
"name": "web-creator",
"private": true,
"workspaces": [
"packages/*"
]
}
We will name our MonoRepo web-creator
. We need to specify that web-creator
will be private (only the root), and we need to specify the workspaces where our packages will live, which is on "packages/*"
; the *
means that we will include any directory that exists under the packages
folder. After this, you need to create the packages directly.
Let’s create two directories inside our new packages
folder...