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:
- Navigate to your angular library project's output directory in a terminal and run the command
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.
- Now navigate to your main application in which your angular library is used as a dependency and run the command
npm link [name_of_your_module]
- Add
"preserveSymlinks": true
to your angular.json file under projects > architect > build
- Run your main application with ng serve, make some changes in your library, build it. Depending on your IDE, you can create a watch task which triggers an automatic build. You should be able to see your changes.
- Finally if you are done testing your changes, you can unlink your dependency from your main application by running the command
npm 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:patho
pmpackpackage"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…