允许在单个打字稿npm包

时间:2017-07-28 22:59:38

标签: javascript typescript npm

我有一个项目(我们称之为FlatEarth),只有客户端,仅服务器和公共组件。我想创建一个单独的npm包,只允许从相关部分导入。

例如,仅客户端项目可以执行以下操作:

import { FeCommon, FeClient } from 'FlatEarth'.

我面临的问题是,即使我只导入FeClient和FeCommon组件,FeServer组件(请求 - 承诺)也会在构建过程中导致错误(因为它们与客户端解决方案不兼容),因为它们仍然被FlatEarth的index.ts文件导入。

FlatEarth设置基本上是:

index.ts

import * as FeCommonStatic from './FeCommon';
import * as FeServerStatic from './FeServer';
import * as FeClientStatic from './FeClient';

export { FeCommonStatic as FeCommon };
export { FeServerStatic as FeServer };
export { FeClientStatic as FeClient };

FeCommon.ts

import * as stringStatic from './String';
import * as uriStatic from './Uri';

export { stringStatic as string };
export { uriStatic as uri };

FeServer.ts

import { ServerRequestHandler } from './Server/ServerRequestHandler'; // Depends on request-promise. 

export { ServerRequestHandler as RequestHandler }

FeClient.ts

import { ClientRequestHandler } from './Client/ClientRequestHandler'; // Depends on jquery

export { ClientRequestHandler as RequestHandler }

0 个答案:

没有答案