-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Publishing module for both Node.js and browser #946
Comments
This is less a TSDX question and more a general library question. There are two ways to go about doing this. One is to create two separate entrypoints, e.g. The other way of going about this is environment or feature detection. Basically you conditionally use certain functionality if you're in Node.js vs. in a browser by e.g. checking if There are other techniques as well, for instance one can compile the same bundle a bit differently and replace variables (like |
Thank you so much for a very detailed answer. Also, thank you for working on an excellent tool |
This question might be a bit misguided so please bear with me - I have never written a JS/TS module for other people to consume.
I'm trying to publish a library that will be consumed both in a Node.js context as well as browser context. I can't seem to figure out how to do that with Tsdx. Specifically, I'm trying to write a helper library that provides a nice integration with Storybook stories (browser context) and Jest (Node.js context).
It seems like all files are compiled into one big
name-of-my-package.cjs.dev/prod.min.js
file. This does not work for me, as that file contains an import of a library which in turn uses Node.js functionality. This then causes my browser code to crash.I guess what I want to do here is to publish two versions of my library: one which exposes the browser methods, and one that exposes the Node.js methods. I want both to be part of the same package. Is this a very strange way of doing things?
Any help here is much appreciated.
The text was updated successfully, but these errors were encountered: