Setting Up Angular Libraries
Generate a blank Angular workspace
Note
--createApplication=false
does not create a default project
Switch to the newly created folder
Generate the library
This creates the library folder inside a projects folderGenerate an example angular test app
Note
The name of the test application should always be `example`
node_modules
. This eases development.
Add build script
In the package.json
add a script to build the library
Build the library
Testing the library in the example project
Import the required modules
Html
Packaging the Library
Add the packaging script
package.json | |
---|---|
Package the library
Amyform-0.0.1.tgz
is created inside the dist folder. This can be uploaded to any repository.
Installing the packaged library
Adding a scope to the name @myorg/library
Edit the myform lib package.json
to reflect the same
projects/myform/package.json | |
---|---|
Building and packaging the libary generates a sisitech-myform-0.0.1.tgz
package, reflecting the added scope name.
Including Assets / Styles when Building the Library
Add "assets": ["./styles/*.*","./assets/*.*"]
into the ng-package.json
file of the library.
ng-package.json | |
---|---|
Using Assets, Javascript & styles Within Your Project
Add the code below to your angular.json
file
angular.json
"assets": [
"projects/example/src/assets"
],
"styles": [
"projects/example/src/styles.scss"
],
"scripts": [
"projects/example/src/my-js-file.js"
]
Resources
Example project with myform Github Repo