Angular libraries : How to switch from npm package to npm sym link?

127 views Asked by At

Within my Angular workspace, I have one Application and one Library.

The library is referenced in the application using a sym link (npm link my-lib) and I updated my tsconfig.json to know about the path of my library:

"paths": {
  "my-lib": [
    "dist/my-lib/my-lib",
    "dist/my-lib"
  ]
}

When I build my library like this :

ng build my-lib --watch

I get live updates, I can instantly see the changes in my Application which is recompiled automatically when using ng serve

Up to this point it's all good. However when I build on my build server, I want to publish my library to npm and use the npm package instead of a sym link.

After publishing my package to npm, I ran npm i my-lib in my Application. The package is installed.

However I no longer get live updates when making changes to my libraries in development. I think this is because the sym link is no longer used and my Application is using the npm package instead.

How do I work around this problem ? I need the package for production, but in development I want to use the sym link. How can I do that ?

1

There are 1 answers

0
Sam On BEST ANSWER

after installing the library from npm feed, the symlink had to be recreated. Simple as that :)