Migrating to pnpm
·
1 minutes read
I’ve been researching on optimization that can be done in one of the project’s CI pipeline. The issue is that the whole process can take a very long time including time to set up the project and running all the tests. So I’ve been looking at pnpm to manage the installation of the JavaScript’s dependencies in the CI.
From my experience, the time taken to install the packages can be reduced to just seven seconds (from around almost two minutes, with cache primed) so this is a very welcomed changes. Every second matters.
Once I got the pnpm installed, it’s pretty much a drop-in replacement for npm.
Here’s a short steps that I’ve taken to migrate an existing JavaScript to use pnpm:
- Delete
node_modules. - Migrate any
workspacesdefined inpackage.jsonto its own specificpnpm-workspace.yaml. - Run
pnpm import. This will allowpnpmto create its own version of the lockfile,pnpm-lock.yamlbased on the current lockfile used in the project (packages-lock.json/yarn.lock). - Install the dependencies via
pnpm i. - Replace any
npm runcommand withpnpm, eg:pnpm buildinstead ofnpm run build.
That’s it!