Allow export of client, server and shared modules independently in one typescript npm package

I have a project (let's call it FlatEarth) with only client, server and shared components. I would like to create a single npm package that only allows import from the relevant parts.

For example, only a client-side project could do the following:

import { FeCommon, FeClient } from 'FlatEarth'.

The problem I am facing is that although I only import the FeClient and FeCommon components, the FeServer (Promise Request) components will throw errors during the build process (since they are not compatible with client solutions) as they are still imported by the file FlatEarth index.ts.

Setting up FlatEarth is essentially:

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 }

      

+3


source to share





All Articles