2

I'm maintaining an Angular library built with the Angular CLI and while I'd like to use the latest version of the Angular tooling I don't want to force consumers of my library to update Angular too often. Is there a way to target an older version of Angular when building a library with the latest version of the CLI?

  • Have you tried removing the "peerDependencies" or lowering the angular version in the package.json of your library? Most of the time your library is built finished code so you can import it and use it however you like. I've had success taking an angular library and using Rollup to package it for standard JS projects. I could also see this working for removing the dependency of a particular angular version if you need to. – Jessy Jan 05 '22 at 14:58

1 Answers1

2

The most common way to do this is to use semver versioning. Basically when there is a new release of angular, you bump your major version after you migrated your code to the new version.

Another common thing to do with an angular library, is to keep the major version number the same as angular. At the time of writing it's angular 9, so your package would have version 9.x.x. When angular 10 releases, and you want to support it, you release your 10.x.x version.

You can even go as far as to add beta releases for angular beta versions. There is already an angular 10.next version, so you can publish your library with angular 10 support, under an angular 10 branch in your version control system. It's common to use the next tag while publishing. This way consumers can install the next version by using the @next version while installing

You can even provide the angular cli with information about your package using schematics. When they use the command ng install your-library-name they will get the appropriate version which matches their angular version, as long as you made the correct settings

Poul Kruijt
  • 69,713
  • 12
  • 145
  • 149