Use yarn to install and uninstall packages

Table of contents

yarn installation package

1. Installation dependencies

2. Install and develop dependencies

3. Install global dependencies

4. Upgrade dependencies

1. Upgrade the version of the specified dependency package

2. Upgrade all dependent package versions

5. Remove dependencies

yarn uninstall package

1. yarn uninstall package

Two, yarn uninstall dependencies

Three, yarn uninstall command

Four, yarn uninstall dependent package command

Summarize

yarn installation package

1. Installation dependencies

Yarn is a modern package manager that helps us manage dependencies in projects more easily. When installing dependencies, you can use the following command:

yarn add [package]

Among them, [package] can be a single dependency or multiple dependencies, and the command will automatically add dependencies to the fields package.jsonin the file dependencies.

2. Install and develop dependencies

In addition to runtime dependencies, there are some dependencies that are only needed during development, such as testing frameworks, code inspection tools, and so on. When installing development dependencies, you can use the following command:

yarn add [package] --dev

This way, installed dependencies are automatically added to the fields package.jsonin the file devDependencies.

3. Install global dependencies

Some dependencies need to be installed locally, others need to be installed globally.

In yarn, you can use the following command to install dependencies globally:

yarn global add [package]

In this way, the dependency can be used in all projects.

4. Upgrade dependencies

As the project progresses, dependent package versions may need to be upgraded. Yarn can easily upgrade the specified dependency package version, and can also upgrade all dependency package versions to the latest version.

1. Upgrade the version of the specified dependency package

In yarn, you can use the following command to upgrade the specified dependency package version:

yarn upgrade [package]

This command will upgrade the version of the specified package to the latest version and update package.jsonthe version of dependencies in the file.

2. Upgrade all dependent package versions

In yarn, you can also use the following command to upgrade all dependent package versions to the latest version:

yarn upgrade

This command will upgrade all dependent package versions to the latest version and update package.jsonthe dependent version in the file.

5. Remove dependencies

In some cases, we need to delete a dependency package in the project. In yarn, you can use the following command to delete the specified dependency package:

yarn remove [package]

This command will remove the specified dependency package from the field package.jsonin the file dependenciesand node_modulesdelete the dependency package from the directory.

yarn uninstall package

1. yarn uninstall package

yarn is an efficient package management tool that helps to install dependent packages easily. However, we also need to know how to uninstall packages, since an application's dependencies may change over time. If you no longer need a package or dependency, you can use yarn to uninstall it. The syntax for yarn uninstalling a package is as follows:

yarn remove package_name

Here "package_name" represents the name of the package that needs to be removed. This command will remove this package from your project dependencies. If the specified package has dependencies, they will also be uninstalled.

Two, yarn uninstall dependencies

Generally, you'll want to remove a package and all of its dependencies. At this time, you can use yarn to uninstall dependencies. The commands for yarn uninstall dependencies are as follows:

yarn remove package_name [--recursive/-r]

You can add the option "--recursive" or "-r" to the command. In this way, yarn will use the structure of the dependency tree to delete the specified package and all its dependencies. This means, if "package_name" is a dependency of other packages, those packages will also be uninstalled.

Three, yarn uninstall command

There are many variations of the yarn uninstall command, and different commands can be selected according to requirements. The following are several commonly used yarn uninstall commands:

yarn remove package_name:卸载指定的包。
yarn remove package_name --save:从项目的依赖中删除指定的包。
yarn remove package_name -D / --dev:从项目的devDependencies中删除指定的包。

Four, yarn uninstall dependent package command

Sometimes, you may only want to remove a certain dependency of your project without removing the entire uninstall dependency. At this time, you can use the yarn uninstall dependency package command:

yarn remove [--production=false] package_name ...

Here, "production" can be a boolean true or false, and the default value is true. When production is true, the uninstall operation only works on dependent packages. When production is false, the uninstall operation works on both the development dependent package and the global dependent package.

Summarize

Yarn is a powerful package manager that helps us better manage dependencies in projects. Understanding the rules of yarn installation dependencies will be very helpful for project maintenance and upgrades. This article details how to install and uninstall packages using yarn. With this guide, you should have seen the different ways how to use yarn to uninstall a package and its dependencies. Through these methods, you can more easily and conveniently manage the dependencies required by your project and adjust them at any time.

Guess you like

Origin blog.csdn.net/qq_44848480/article/details/131432916