How to use yarn link

introduce

You can operate the yarn package you want to debug across projects and files . You don’t need to release it every time, as long as it is your own computer, because the yarn link is stored in the memory of yarn. It is equivalent to opening a channel.

During development, when two projects or multiple projects depend on each other, use  yarn linkconnection. For example: we now have project B, and B uses npm/yarn package manager to introduce package A. A is a component developed and packaged by ourselves. We have modified the content of component A. Before re-publishing component A, we want to check whether the modification of component A is correct in project B. At this time, we need to useyarn link

principle

In essence, it is to set up soft links in the global yarn installation directory

Method
Run yarn link under the developed package file (same level as packagejson) 


Then there will be a sign of success link xxxx (package name) At this time, your development package is already in memory

Run yarn link (package name) in the root directory of the project that needs to be applied, a success prompt will appear, and then if the current project is running, it will automatically recompile

It should be noted that
1. Before yarn link, you need to ensure that your nodelmodues or lib.js is up-to-date, so you need to build it, and execute yarn link

2. If the source code of the development package is jsx and vue, it cannot be yarn linked. Webpack will not package external resources, and the browser cannot recognize them. They need to be compiled before they can be recognized.

Unlink
Correspondingly execute yarn unlink and yarn unlink (package name)

Guess you like

Origin blog.csdn.net/weixin_53841730/article/details/128283990