Allow export of Client, Server and Common modules independently in a single typescript npm package

Viewed 72

I have a project (lets call it FlatEarth) with client-only, server-only and common components. I would like to create a single npm package that allows importing from only the relevant portions.

For example, a client-side only project would be able to do the following:

import { FeCommon, FeClient } from 'FlatEarth'.

The issue that I am facing is that even though I am only importing the FeClient and FeCommon components, the FeServer components (request-promise) will cause errors in the build process (since they are not compatible with client solutions) since they are still being imported by FlatEarth's index.ts file.

The FlatEarth setup 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 }
0 Answers
Related