Kabir Roy Kabir Roy - 8 days ago 5
Git Question

Can Angular 2 components be externalised?

TL;DR

Is it possible to have something like

package.json
for components in an Angular 2 app?

Long Version

The components of our application are being developed independently. They have their own services, constants and internationalisation strings. Every time there is an update or change to a component the application version is updated. Is there a way we could just version a component and have separate repositories for each component; each being stated as a dependency of the main app?

My Thoughts


  • Create a dummy app on each machine that is used to develop a component

  • Work with the component and commit it to a repository

  • The main app's build process specifies those repositories as dependency and pulls them (specific version) during build time.

  • Another task copies them into the application directory (from
    node_modules
    )



Question

Has anyone already done this before? Is there a better way of doing this?

Answer

It's simpler than I thought. Just move the component files out of the app as a separate module. npm install --save it to the app and update the app.module.ts file to point at it. Angular CLI will automatically handle the rest.

app.module.ts

import { ProfileCardComponent } from '@yoloinc/profile-card-component/profile-card.component';

Comments