If I create an angular library like this:
ng new libraries-workspace --create-application=false
cd libraries-workspace
ng generate library test-library
And now I build the library
ng build test-library --watch
Now if I create a new angular application in a completely different folder (away from the workspace)
ng new test-project
cd test-project
How can I reference or install my library without publishing to NPM. So basically I want to install the library from a folder
something like this:
ng add test-library c:\libraries-workspace\dist\test-library...
I don't want to add my project to the workspace folder.
Thanks
Edit 07.02.2021: An easier way
You can link your angular library directly to your application of choice, e.g. your main app. To do so, follow these steps:
npm link. You may have to trigger ng build once, so that the output directory exists. This will make your library locally available on your machine.npm link [name_of_your_module]"preserveSymlinks": true to your angular.json file under projects > architect > buildnpm unlink [name_of_your_module] in your main application's root directory. Go to your angular library project directory and run npm unlink so that your library isn't locally available anymore. You can now publish your changes and intall your latest version with npm install in your main application.Remember it has to be the dist output folder since the angular cli does not support directly linking your library. You can also link libraries to other angular libraries in the same way, but you will have to add "preserveSymlinks": true to your library's tsconfig.json
Old answer:
You have to first pack the build output of your library. For that you have to use npm pack command inside the build output folder. Npm pack will create a package, copy the path of the created package, navigate to your test project in the terminal and hit npm install "C:\path\to\npm\pack\package"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With