Add CommonJS Build
JaneX8 opened this issue · 1 comments
Feature Request: Add CommonJS Build
Describe the problem
The current build of the library only supports ECMAScript (ES) module format, which makes it difficult for developers who use CommonJS in their projects to use this library.
Describe the solution you'd like
I would like to request the addition of a CommonJS build to the library. This will allow developers who use CommonJS to easily use this library in their projects.
Describe alternatives you've considered
One alternative solution would be to manually transpile the library using Babel or a similar tool. However, this can be time-consuming and error-prone. Having a CommonJS build as part of the library will make it easier and more convenient for developers to use it.
Additional context
I'm trying to use this in a serverless function on a platform that only supports CommonJS for the moment. Making this library unfortunately not easily usable at the moment.
Hi again @JaneX8! Agreed, we should support CommonJS.
I tried to when I first started working on this library, but gave up as I couldn't get the two working and I couldn't think of any reason why we'd want to support CommonJS going forward, but yours is a good reason.
I'd welcome a PR for this if you want to tackle this. A few relevant pointers:
- We have many JS repos on this organisation as you can tell, so we try to factor out as much as we can to avoid duplication. In this particular case, all of our projects inherit their TS config from: https://github.com/relaycorp/shared-config/blob/master/tsconfig.json
- Unlike this repo, most of our JS repos actually output CJS and ESM. Here's an example, which I think could be a good starting point: https://github.com/relaycorp/relaynet-core-js/blob/29fff4ed46350e06f2db85c581b633e2b63cccc1/package.json#L20-L22.
- Packages like
relaynet-core-js
don't actually support ESM because thepackage.json
file lacks the appropriate changes. This is the part I never managed to get to work: For some reason, I always end up with a config that supports either CJS or ESM, but not both. I'm sure I'm doing something wrong, but I don't know what exactly.