Is there a way to publish an angular app (which is wrapped as a web component using Angular Elements) as an npm package? I'm looking to import the web component in another app through npm as opposed to copying script files and including them in the angular.json.
I have created an angular app, successfully wrapped the app as a webcomponent using Angular Elements, created a separate main app to consume the component, imported the script files into the main app through the angular.json file, and successfully rendered my web component in the main app using the web component element tags.
Here is some of my code:
Web Component module
@NgModule({
declarations: [AppComponent, ExplorerComponent],
imports: [
BrowserModule,
AppRoutingModule,
MultiViewerModule,
StoreModule.forRoot({
viewerConfig: viewerReducer
}),
CommonPlotsModule.forRoot(environment),
StoreDevtoolsModule.instrument(),
HttpClientModule
],
entryComponents: [ExplorerComponent]
})
export class AppModule {
constructor(injector: Injector) {
const explorer = createCustomElement(ExplorerComponent, {injector});
customElements.define('plots-element', explorer);
}
ngDoBootstrap() {
}
}
Main App module:
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, AppRoutingModule],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
App Component in main app:
<plots-element></plots-element>
I am exploring importing the web component app from the dist folder but I haven't had any luck yet.
How can I create an npm package of an Angular Elements component which I can import into other apps?