npm install still too slow?
npm performance optimization pnpm build frontend english
Today we have a big choice of package managers for our frontend apps such as JSPM, NPM, Yarn, Bower, etc.. Some of them has been outdated and some of them still grow its popularity such as NPM and Yarn. And everybody who worked with NPM faced with huge size
npm_modules directory and dependencies hell in our apps. All these leads us to big performance gaps in build pipelines of our apps.
One of project on which I've worked on has NPM as main package manager and
npm install command takes almost 3 minutes on our CI builds. And of course this time still grows with growing our app. Some of devs suggest us to use Yarn, but in this case we will have to face with Migrating to Yarn from NPM. In some ways this is a pretty good solution, but I would to go deeper and found for myself nice solution which nice fit for all our team.
Solution is PNPM!
PNPM - Fast, disk space efficient package manager.
- Fast - pnpm is as fast and sometimes even faster than NPM and Yarn (see benchmarks)
- Efficient - One version of a package is saved only ever once on a disk. So you save dozens of gigabytes of disk space!
- Strict - pnpm creates a non-flat
node_modules, so code has no access to arbitrary packages
- In our case after installing pnpm we've just renamed
package.jsonfile and build time on our CI decreases from 3 minites to 30 seconds (in 6x times!).