DEV Community

Discussion on: Getting Started Building Component Libraries with Angular CLI

Collapse
 
anandu06 profile image
anandu06

Looks Simple & Clear!

Having few Questions ..

how to use the library in another angular project without publishing in npm?

Collapse
 
nieds profile image
Brenden Niedermeyer (he/him)

If you generated the library in the same workspace as the project you want to use you should be able to use it right away (just make sure build the library before the project). If your project is separate from the workspace you are developing your library in you can use the npm link method mentioned above while you are working on the project.

If you need the project to build in a different environment (a build system like travis for example) and don't want to publish to npm you can either

a) publish to a private registry (for example nexus or verdaccio) and point to that
b) build the library and manually include the files in your other Angular project and configure your tsconfig of the project to point to the library similar to the way it's setup when you generate a new library in the same workspace.

// tsconfig.json
{
  "compilerOptions": {
    ...
    "paths": {
      "my-new-library": ["my-new-library"]
    }
  }
}

I haven't tried the second approach so there may be other issues (like maintaining your peer dependencies of the library) that could complicate matters. I generally find it easier to publish to private registries. Another option would be paying for private package hosting on npm.