[英]Developing a local npm package
I am developing a npm package.我正在开发一个 npm 包。 Lets call it
my-library
.让我们称之为
my-library
。 I publish this package to a private npm repository which is pulled by many of my projects.我将此包发布到一个私有 npm 存储库,该存储库由我的许多项目提取。 How can I quickly develop the code in
my-library
without having to publish a new version of my-library
every time I make a small change?如何在
my-library
中快速开发代码,而不必每次进行小的更改时都发布新版本的my-library
?
Take the following workflow for example:以以下工作流程为例:
my-library
.my-library
进行了更改。 The change is still in development so I don't want to publish it to all my consumers yet, but I do want to test it locally.npm pack
to create a local .tgz
file.npm pack
来创建一个本地.tgz
文件。my-consumer
I update the package.json
to reference this local .tgz
file.my-consumer
,我更新了package.json
以引用这个本地.tgz
文件。 "my-library": "file:../some/path/my-package.tgz"
npm install
in my-consumer
and my local package is not installed and I can test my app.my-consumer
中运行npm install
并且我的本地包没有安装,我可以测试我的应用程序。 Now, there isn't anything apparently wrong with the aforementioned steps, but say I am very quickly iterating on my-library
and I want to make and test changes very quickly.现在,上述步骤没有任何明显错误,但是说我正在非常快速地迭代
my-library
,并且我想非常快速地进行和测试更改。 Is there any way I can make the above process go faster?有什么办法可以使上述过程更快? Running pack and install for every little change takes time and is much slower than if this were hot-reloading.
为每一个小改动运行打包和安装都需要时间,而且比热重载要慢得多。 Can I configure my package.json in
my-consumer
to use a cached version of my-library
that is not in the node_modules folder and skip some of the above steps?我可以在
my-consumer
中配置我的 package.json 以使用不在 node_modules 文件夹中的缓存版本的my-library
并跳过上述一些步骤吗? I also don't want this to introduce any dependency issues.我也不希望这会引入任何依赖问题。
I'm using npm/yarm link for that.我正在为此使用 npm/yarm 链接。 it allows you to symlink your library to your project, and therefore have the most updated code without any publish and install.
它允许您将库符号链接到您的项目,因此无需任何发布和安装即可拥有最新的代码。
Basically the syntax is:基本上语法是:
cd /path/to/lib
yarn link
cd /path/to/project
yarn link myLibName
Take a look at the yarn link
docs .看看
yarn link
文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.