Install pnpm
Remove node_modules
shell
npx npkillAdd a preinstall Hook
json
{
"scripts": {
"preinstall": "npx only-allow pnpm"
// ...
}
}(Optional) Create pnpm-workspace.yaml
TIP
This touches on a software development strategy called monorepo.
yaml
packages:
# include packages in subfolders (change as required)
- 'apps/**'
# all packages in direct subdirs of packages/
- 'packages/**'
# exclude packages that are inside test directories
- '!**/test/**'Remove workspaces from package.json.
(Optional) Warning When Running pnpm add
Add the
-wflag when installing:shellpnpm add <pkg> -wINFO
Some third-party scripts run
pnpm addautomatically, so you may not control the CLI options—see the next approach.This might not be the best practice in a
monoreposetup.Create an
.npmrcfile in the project root with the following content:textignore-workspace-root-check=true
Generate pnpm-lock.yaml from package-lock.json
shell
pnpm importRemove package-lock.json
shell
rm -f package-lock.jsonInstall Dependencies with pnpm
shell
# Alias: pnpm i
pnpm installReplace npm run xxx with pnpm xxx
json
{
"scripts": {
"test": "npm run test",
"test": "pnpm test"
}
}