Angular 5:是否可以 link 本地 npm 模块?

Angular 5: Is it possible to link a local npm module?

我有一个自定义节点模块,我无法在 NPM 上发布。

我想将它用作 NPM 上的任何模块。

是否可以不将文件夹复制到 node_modules 中?

答案是:是的,这是可能的

假设您的模块有一个 dist 文件夹,其中包含内置源 (例如,我在 src 文件夹中 运行 gulp 并生成 dist 文件夹)。

您只需 运行 npm pack ./dist 在您的图书馆中。

this will produce a tgz archive with your library named your-library-version

然后你可以通过简单地 运行ning

在你的项目中安装你的模块

npm i path-to/your-library-version.tgz

大功告成。

假设我的图书馆管理员是 C:\ngx-mat-lib

所以我的 tgz 将在这个文件夹中,因为 dist 文件夹应该是 ngx-mat-lib 的子文件夹。

在我的项目中,我将 运行

npm i C:/ngx-mat-lib/ngx-mat-lib-0.0.1.tgz

Note: using forward slashes to avoid doubling them