angular-cli库创建辅助入口点 [英] angular-cli library create secondary entry point
问题描述
我正在尝试在我的angular npm软件包中创建我认为称为辅助入口点的东西。我想要以下两个入口点
I am trying to create what I believe is called a secondary entry point into my angular npm package. I want the following two entry points
@scope/data-service
@scope/data-service/models
使用angular-cli生成基本包会生成以下结构
Using the angular-cli to generate the base package generates the following structure
scope
└───data-service
│ karma.conf.js
│ ng-package.json
│ ng-package.prod.json
│ package.json
│ tsconfig.lib.json
│ tsconfig.spec.json
│ tslint.json
│
└───src
│ public_api.ts
│ test.ts
│
└───lib
data-service.component.spec.ts
data-service.component.ts
data-service.module.ts
data-service.service.spec.ts
data-service.service.ts
基于ng-packagr 文档,您可以在名为 models的数据服务下添加一个文件夹,然后向该文件夹添加第二个 package.json
,但是ng-packagr似乎使用了与angle-cli的结构略有不同。理想情况下,我正在尝试对类似于 https://github.com/angular的结构进行建模/ angular / tree / master / packages / common ,但只要向公众公开是 @ scope / data-service
和 @scope / data-service / models
我会很高兴。
Based on ng-packagr documentation you would add a folder under data-service called models then add a second package.json
to that folder but ng-packagr seems to use a slightly different structure than the angular-cli. Ideally I am trying to model the structure similar to https://github.com/angular/angular/tree/master/packages/common but as long as the public exposed is @scope/data-service
and @scope/data-service/models
I would be happy.
当我尝试创建类似于ng-packager建议的结构时,我会得到
When I try to create the structure similar to ng-packager recommendation I get
错误TS6059:文件'C:/projects/data-service-app/projects/scope/data-service/models/src/index.ts '不在'rootDir'下'C:\projects\data-service-app\projects\scope\data-service\src'。 'rootDir'应该包含所有源文件。
当我将models目录移到 data-service中时\src
目录,我的入口点是
When I move the models directory into the data-service\src
directory my entrypoints are
@scope/data-service
@scope/data-service/src/models
如何在辅助入口点摆脱src ?
How do I get rid of the src on my secondary entry point?
使用angular-cli创建带有辅助入口点的库的正确方法是什么?
What is the correct approach for creating a library with a secondary entry point when using the angular-cli?
推荐答案
辅助入口点的文件夹布局示例
Example Folder Layout for Secondary Entrypoints
所有您需要做的就是创建一个 package.json
文件,并将其放在您想要创建辅助入口点的
位置。
的一种实现方式是模仿以下示例的文件夹结构,其中
除其主入口点外还具有测试入口点。
All you have to do is create a package.json
file and put it where you
want a secondary entry point to be created. One way this can be done
is by mimicking the folder structure of the following example which
has a testing entry point in addition to its main entry point.
my_package
├── src
| ├── public_api.ts
| └── *.ts
├── ng-package.json
├── package.json
└── testing
├── src
| ├── public_api.ts
| └── *.ts
└── package.json
<$的内容c $ c> my_package / testing / package.json 可以很简单:
{
"ngPackage": {}
}
不,这不是错字。不需要名称。不需要版本。
这一切都由ng-packagr处理!建好后,主入口
点由 import {..}从'@ my / library'
导入,而
辅助入口点以从 @ my / library / testing导入{..}
No, that is not a typo. No name is required. No version is required.
It's all handled for you by ng-packagr! When built, the primary entry
point is imported by import {..} from '@my/library'
and the
secondary entry point with import {..} from '@my/library/testing'
来源- https://github.com/ng -packagr / ng-packagr / blob / master / docs / secondary-entrypoints.md
这篇关于angular-cli库创建辅助入口点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!