0.1.5 • Published 2 years ago
les-proto-package v0.1.5
LesProtoPackage
This is a prototype package to test how to form libraries in Angular. The package includes an Angular component, service, pipe, and a directive to test functionality.
How to make a library and turn it into npm package using Angular
- Make sure that you have an npm account to sign-in and publish your library as well as nodejs and npm installed in your environment.
- Create a workspace with the command
ng new <work-spae> --create-application=false
. The flag prevents Angular from building the default application so that we can work on a clean empty workspace. - Create a library with the command
ng generate library <library-name>
- Put any component, service, pipe, directive, etc. in the generated library directory most likely under
projects/<library-name>/src/lib/
. You can generate any new Angular class by using thegenerate
command. Ex:ng generate pipe <pipe-name>
- Make sure that any Angular class you want to use is exported through
public-api.ts
and the.module.ts
files. Ex: inpublic-api.ts
export * from './lib/italic-highlight.directive';
. In.module.ts
,exports: [LesProtoPackageComponent, ItalicHighlightDirective, NoSAllUPipe]
- Build the library with the command
ng build
- Login to the npm registry with
npm login
and navigate to the dist directory generated after building the librarycd dist/<library-name>
. - Publish the library with
npm publish
.
How to update your library
If you want to update your library package, just repeat the steps from 6 to 8 but increment the version in package.json
under dist/library
after building and then publish again.