Yarn
Yarn is package manager for JavaScript projects, but it solves some problems that the native npm exists.
Characteristic
Consistent Depedency Version
Yarn uses yarn.lock
to lock the versions of the dependencies of packages. The reason of this is because package.json
using by npm may using different version of dependencies, but Yarn always refers the version locked in yarn.lock
.
Parallel Installation
The main reason convincing me to use Yarn instead of npm is this one. (As I think package-lock.json
should locked the versions, too) Npm installs the packages sequentially, but Yarn installs in parallel. This greatly reduces the time used for installing packages.
Compatibility
Yarn depends on npm, except extra yarn.lock
is added. The use of package.json
is not affected, so it's available for switching from Yarn to npm.
Commands
Here only lists commands that are mostly used.
List commands
Init New Project
Install dependencies listed in package.json
normally, this command updates yarn.lock
.
with --frozen-lockfile
flag, does not updates yarn.lock
and ensures the version in different environment are same. Error will throw if the version between package.json
and yarn.lock
are not compatible.
with --offline
flag, the installation does not use online resource (local cache instead), so it's even faster and only valid if the packages exist before and the command is run before.
Add dependencies...
... for different environments
Upgrade dependencies
Remove dependencies
Upgrade Yarn
Last updated