NPM: only installation is missing - how to speed up npm installation

I have a lot of devdecencances in my npm script. npm install takes a few minutes for the first time, this is normal.

But since I integrate with the TFS build server, it only needs to install npm once. After that, npm install just wastes time because it takes 2-3 minutes to identify packages. In addition, it seems that it always reinstalls packages with the -g global flag, even if it exists.

How can I check if packages exist, and if so, skip npm install?

+5
source share
1 answer

You can use npm-cache as an alternative way if you use built-in agents in place for assembly.

This is useful for build processes that run [npm | bower | composer | jspm] install each time as part of the build process. Since dependencies often do not change, this often means slower build time. The NPM cache helps resolve this problem by caching previously installed build machine dependencies. npm-cache can be a drop-down replacement for any build script that runs [npm | bower | composer | jspm] install.

How it works

When you run npm-cache install [npm | bower | jspm | composer], first looks for package.json, bower.json or composer.json in the current working directory, depending on which dependency manager is requested. Then it computes the MD5 hash of the configuration file and looks for a file named .tar.gz in the cache directory ($ HOME / .package_cache by default). If the file does not exist, npm-cache uses the installed dependency manager to install the dependencies. Once dependencies are installed, npm-cache tars recently loaded dependencies and saves them in the cache directory. The next time npm-cache launches and sees the same configuration file, it will find the tarball in the cache directory and unlock the dependencies in the current working directory.

And you can also try npm-install-missing .

However, if you use the VSTS Hosted Build Agent, then you cannot do this, because every time you queue the build with the Hosted Build Agent, a clean build agent is assigned to build. This means that the dependency package is not installed on the agent. You need to complete a full npm installation.

+5
source

All Articles