Jov*_*ani 6 git npm npm-install angular angular-library
问候,我已经创建了一个 angular 库,并且已经将它构建并推送到 gitlab 的私有仓库中,现在我需要在另一个项目中使用它
所以我尝试使用 package.json 中的以下行导入它
"my-core-lib": "git+ssh://git@gitlab.com:<username>/my-core-lib.git"
Run Code Online (Sandbox Code Playgroud)
但那是下载了整个 repo 并将其放在 node_modules 中,包括“dist”文件夹
我需要导入“dist”文件夹的内容,而不是整个 repo,例如:
"my-core-lib": "git+ssh://git@gitlab.com:<username>/my-core-lib.git/dist"
Run Code Online (Sandbox Code Playgroud)
提前致谢
如果包源托管在 GitHub 上,您可以像这样使用GitPkg :
# using npm:
npm install https://gitpkg.now.sh/<user>/<project>/<subdir>?<commit-ish>
# using yarn:
yarn add https://gitpkg.now.sh/<user>/<project>/<subdir>?<commit-ish>
Run Code Online (Sandbox Code Playgroud)
他们的站点上有一个类似向导的表单,可以帮助构建 URL 以及安装它的命令。
如果您构建自定义库,并且入口点不在其 Git 存储库的根目录中,那么您只需执行一些安装后处理 - 将源代码移动到正确的位置。
或者,您还可以应用文件过滤器,以便npm从存储库中仅复制模块中所需的文件/目录。
编辑package.json并添加两行:files和scripts-> postinstall,使文件如下所示:
{
"name": "my-custom-angular",
"version": "1.0.0",
"main": "index.js",
"files": ["dist"],
"scripts": {
"postinstall": "mv ./dist/* ./ && rmdir ./dist"
}
}
Run Code Online (Sandbox Code Playgroud)
GL!
| 归档时间: |
|
| 查看次数: |
3257 次 |
| 最近记录: |