我正在使用Angular库,该库使用public-api.ts导出应用程序的元素,以便其他使用中的应用程序可以使用它们。例如:
public-api.ts:
export * from './lib/core.module';
export * from './lib/components/header/header.component';
export * from './lib/components/layout/layout.component';
export * from './lib/components/tenant-nav/tenant-nav.component';
export * from './lib/components/left-menu/left-menu.component';
export * from './lib/services/config-resolver.service';
export * from './lib/common/types';
export * from './lib/common/const';
我有一个lib / common / const文件夹,其中包含导出常量的文件。例如,这是一个文件:
export const LEFT_MENU_EVENT = 'Base.Menu.LeftMenuEvent';
export const APP_MENU_EVENT = 'Base.Menu.AppMenuEvent';
在我的库中,我可以使用
从一个特定文件导入变量。import * as CONSTANTS from './constants/myfile'
我只希望在使用的应用程序中从库中导入常量文件。这是我希望工作的声明:
import * as CONSTANTS from '@mylibrary/const'
这怎么办?似乎public-api.ts文件中导出的所有内容都变平了。我希望引用库中与
类似的子文件夹import { Component } from '@angular/core'
答案 0 :(得分:1)
我找到了一种将文件导出为名称空间而不是导出子文件夹的方法。这可以达到目的:
export * from './lib/core.module';
...
import * as ALL_KEYS from './lib/common/const';
export { ALL_KEYS };
然后我输入为:
import { ALL_KEYS } from '@mylibrary';