在本地构建和使用npm包 [英] Build and use npm package locally

查看:191
本文介绍了在本地构建和使用npm包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ngx-mask软件包中进行了一些自定义修改,需要在本地进行测试.

I made some custom modifications in the ngx-mask package and need to test it locally.

如何覆盖已安装的npm软件包?

How to overwrite the installed npm package?

当前,该程序包在packages.json文件中被声明为依赖项:

Currently the package is declared as a dependency in packages.json file as:

"ngx-mask": "^7.8.9"

如果可能的话,我宁愿不要分叉原始软件包,也不要为此使用github.

I do prefer not to fork the original package and not to use github for this, if possible.

推荐答案

如果在计算机上进行了这些更改. (我假设你有)

If you have made these changes on your machine. (I'm assuming you have)

  1. 运行已更改的ngx-mask程序包的build.

导航到dist/不论编译的输出文件夹是什么.

navigate to the dist / whatever your compiled output folder is.

在该文件夹中运行npm pack.这会使用您的自定义修改为您的软件包创建一个.tgz压缩文件.

run npm pack inside that folder. This creates a .tgz zip file of your package with your custom modifications.

将该文件复制到项目的根目录(您可以将其放在任何地方,但使用root可以使事情变得容易).

copy that file into the root (you could put it wherever but root makes things easy) of your project.

将版本号ngx掩码替换为以下"ngx-mask": "file:my-packed-file.tgz"

in your package.json replace the version number ngx mask to the following "ngx-mask": "file:my-packed-file.tgz"

使用新的package.json

您应该将修改后的副本作为依赖项加载到node_modules中.

you should have your modified copy loaded in as a dependency in node_modules.

这篇关于在本地构建和使用npm包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆