How to reuse Angular modules in other projects

I need to share a custom angular 2 module with other projects in my company.

For example:

@NgModule({
  declarations: [
    AppComponent,
    BannerInlineComponent,
    WelcomeComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class SpecialModule { }
      

Run codeHide result


Now I want to use it in other projects using:

npm install my-special --save

      

And use:

import { SpecialModule } from 'my-special';

      

+3


source to share


1 answer


I found one option using Joeman's generator for angular library:

generator-angular2-library

A generator that creates the base of your module.



After that, I simulated publishing my custom module to local NPM using:

Sinopia

Image of sinopia docker

0


source







All Articles