简体   繁体   English

带有 NPM 和 GIT 的 Angular 包:repo 中的 dist 文件夹?

[英]Angular package with NPM and GIT: dist folder in the repo?

What I want to achieve:我想要达到的目标:

I've created an Angular module and I want to npm install it from my GIT repo (I don't want to use npm publish , because it is a private code) in other projects.我已经创建了一个 Angular 模块,我想在其他项目中从我的 GIT 存储库中npm install它(我不想使用npm publish ,因为它是私有代码)。

I'm using ng-packagr ( https://github.com/dherges/ng-packagr ) to get Angular Package Format.我正在使用ng-packagr ( https://github.com/dherges/ng-packagr ) 来获取 Angular 包格式。 This creates a dist folder to the newly created package.这会为新创建的包创建一个dist文件夹。

This is how I install mypackage with GIT for example:这就是我使用 GIT 安装 mypackage 的方式,例如:

npm install https://SOMETHING/SOMETHING.git#v0.1.0

What my problem is:我的问题是:

My problem is that I've tried these two thing, but both of them are ugly or bad, I think:我的问题是我已经尝试过这两件事,但它们都很丑陋或不好,我认为:

  1. I pushed everything to my GIT repo (I removed dist from .gitignore ), but after npm install and npm start I get a module not find error.我将所有内容推送到我的 GIT 存储库(我从.gitignore删除了dist ),但是在npm installnpm start我收到一个模块未找到错误。 I don't think that this even works, because the package is in the subfolder dist (I import my module from node_modules/mypackage/dist ).我认为这甚至不起作用,因为包位于子文件夹dist (我从node_modules/mypackage/dist导入我的模块)。 The other problem is that when I install the package, my source files are there too, and that is not the best.另一个问题是,当我安装软件包时,我的源文件也在那里,这不是最好的。

  2. I pushed only the dist folder to the GIT repo.我只将dist文件夹推送到 GIT 存储库。 Then I can install it easily in another project, and it works, there are no errors.然后我可以轻松地将它安装在另一个项目中,并且可以正常工作,没有错误。 But my problem with this is that I should push my code somewhere else too.但是我的问题是我也应该将我的代码推送到其他地方。 With this I have to have 2 GIT repos.有了这个,我必须有 2 个 GIT 存储库。 One for my actual code, and one for the package ( dist folder).一个用于我的实际代码,另一个用于包( dist文件夹)。

I know there has to be some kind of better solution.我知道必须有某种更好的解决方案。 I read a lot of articles, but I found nothing.我读了很多文章,但我什么也没找到。

Can anyone suggest a good solution for this?任何人都可以为此提出一个好的解决方案吗? Or should I go with the second one?还是我应该选择第二个?

I'm afraid that if you really want to install it from a git repository you'll have to have 2 repos.恐怕如果您真的想从 git 存储库安装它,则必须拥有 2 个存储库。 I recently had to migrate a similar project and we used a private npm registry .我最近不得不迁移一个类似的项目,我们使用了一个私有的 npm 注册表 The idea is to host your own packages into your private npm registry so only users with the correct credentials can install your packages.这个想法是将您自己的软件包托管到您的私有 npm 注册表中,以便只有拥有正确凭据的用户才能安装您的软件包。 We used Azure artifacts because the user was already using Azure but AFAIK it has some free tier and is really easy to setup.我们使用Azure 工件是因为用户已经在使用 Azure,但 AFAIK 它有一些免费层并且非常容易设置。

您可以在 npm 注册表中使用不同的范围推送它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM