I have created a generic framework for creating dashboards which consists of multiple modules using Angular-CLI.
Some modules are completely independent. Developers who are using this library can add the modules on their project on demand. I had a previous version of this framework created in Angular Js 1.0, in this I have delivered as javascript min files.
What are the things I have to take care to create this Library as private not for public or is there any way to package my modules as separate and deliver without NPM?
This question boils down to two independent tasks: Creating the library package and publishing it internally.
Create the library package
In order to create a library with AOT support, you need to compile it using ngc -p src/tsconfig-aot.json.
tsconfig-aot.json is a copy of tsconfig.json with an additional section:
"files": [
"./app/index.ts"
],
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"genDir": "../dist/out-lib-tsc",
"skipMetadataEmit" : false,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"flatModuleOutFile": "libname.js",
"flatModuleId": "libname"
}
I need to fix the directory structure by moving the files from src/app to the root of the output directory. Then you copy src/app and src/asserts to the output directory.
There are several detailed guides out there. For example Distributing an Angular Library - The Brief Guide
Publish the library package
There are several options to publish private libraries:
- reference a branch in a git repository Note: It is probably a good idea to use different repositories for developing (without compiler output) and publishing
- npm offers private repositories for a fee
- you can setup a local registry (for example Artifactory or Sinopia)
来源:https://stackoverflow.com/questions/45246569/how-to-write-a-reusable-private-library-for-angular-2