Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reuse Angular 2 module in other app without publishing to npm?

Say you have two different Angular 2 apps and both of them need to make use of the same component.

I created the common component, made a library following this tutorial http://blog.angular-university.io/how-to-create-an-angular-2-library-and-how-to-consume-it-jspm-vs-webpack/, but npm will make my code public and I will have to pay to make it private.

So, the questions are:

  1. How should I create components the can be available for the work team?
  2. Is it necessary to publish to npm or can I just push my code to private github repo? And if so, how should I do that and what would be the process to reuse the code in an app?

Thanks in advance.

like image 935
Alina Avatar asked Oct 18 '16 19:10

Alina


People also ask

Can we have multiple app modules in Angular?

Only one root module can exist in an Angular application.

Which file contains a reference to other third party installation in Angular?

The node modules folder is the default folder where all 3rd-party libraries are installed, according to which our application runs. This is used for development purposes. When we run or build our project then only required libraries are put together in a bundle and then deploy into the server.


1 Answers

package.json allows you to reference packages downloaded from a git repository, and this could be the one you use internally. See NPM documentation

Example of formats:

git+ssh://[email protected]:npm/npm.git#v1.0.27
git+ssh://[email protected]:npm/npm#semver:^5.0
git+https://[email protected]/npm/npm.git
git://github.com/npm/npm.git#v1.0.27

So this would in your package.json give something like:

"dependencies": {
   "privatepackage":"git://localgitserver/git/privatepackage.git"
}
like image 199
jornare Avatar answered Oct 16 '22 07:10

jornare