问题描述
我创建了一个通用框架来创建仪表板,该框架使用Angular-CLI包含多个模块.
I have created a generic framework for creating dashboards which consists of multiple modules using Angular-CLI.
某些模块是完全独立的.使用该库的开发人员可以根据需要在其项目中添加模块.我在Angular Js 1.0中创建了此框架的先前版本,在此我以javascript min文件的形式提供.
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.
将这个库创建为私有库而不供公共使用时,我需要注意些什么?是否有办法将我的模块打包为单独的库,并且在没有NPM的情况下进行交付?
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.
为了创建具有AOT支持的库,您需要使用ngc -p src/tsconfig-aot.json
进行编译.
In order to create a library with AOT support, you need to compile it using ngc -p src/tsconfig-aot.json
.
tsconfig-aot.json是tsconfig.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"
}
我需要通过将文件从src/app移至输出目录的根目录来修复目录结构.然后将src/app和src/asserts复制到输出目录.
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.
那里有一些详细的指南.例如分发Angular库-简要指南
There are several detailed guides out there. For example Distributing an Angular Library - The Brief Guide
有几种发布私有库的选项:
There are several options to publish private libraries:
- 在 git存储库中引用分支注意:使用不同的存储库进行开发(不带编译器输出)和发布可能是一个好主意
- npm为费用 提供私有存储库
- 您可以设置本地注册表(例如 Artifactory 或 Sinopia )
- 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)
这篇关于如何为Angular 2+编写可重用的私有库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!