jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.26k stars 508 forks source link

Support separate client and server bundles #751

Closed flybayer closed 4 years ago

flybayer commented 4 years ago

Current Behavior

Currently tsdx only generates one single bundle.

Desired Behavior

We are using tsdx for Blitz.js and we need separate client and server bundles. The Blitz package has (1) code that is isopmorphic and (2) code that only runs on the server.

Currently we have two separate packages to accomplish this but it's a huge mess for code organization because we can't organize code by feature. Code for a certain feature has to be separated in two separate packages. Instead we want all this code to be in a single package.

And then we want to be able to import a specific bundle, maybe like this:

import stuff from 'pkg/client'
import stuff from 'pkg/server'

Suggested Solution

I'm not sure the best way to do this, but I could image having a file structure like this:

src/client.ts      //re-exports from all client.ts files
src/server.ts      //re-exports from all server.ts files
src/featureA/client.ts
src/featureA/server.ts
src/featureA/shared.ts

Who does this impact? Who is this for?

Anyone writing packages that have different functionality on client vs server.

Describe alternatives you've considered

Custom rollup config which I don't know how to do 😅

Additional context

https://github.com/blitz-js/legacy-framework/issues/928

agilgur5 commented 4 years ago

Currently we have two separate packages to accomplish this but it's a huge mess for code organization because we can't organize code by feature.

I don't think this is a technical limitation of using separate packages, you probably just need some build tooling to support importing out-of-tree instead of under the package's root directory. Some monorepos do have out-of-tree importing when those repos are closely tied together as far as I know.

And then we want to be able to import a specific bundle, maybe like this:

That specifically (which I'm not sure is totally necessary per above comment) would be a request for multiple entry points, which would be a duplicate of blitz-js/legacy-framework#841 and the WIP old PR for that blitz-js/blitz#367 .