Shared code between multiple entrypoints
We are building a package (cjs + esm) so we can't use splitting. We have 2 entry points, each one depends on a config file which contains an update-able config variable.
The problem we're facing now is that when we call setConfig imported from entry point A, it updates the config, but the code from entry point B won't be able to consume that new config, beach each generated entry point will have its own copy of the config file.
How do we make the config file a single instance between the 2 entry points?
Code splitting is still very experimental in esbuild and it only supports esm. There is a tsup/cjs-splitting to polyfill it in this way:
- Bundle the package with
format: 'esm', splitting: true, now you get many esm files. - Transform these files to cjs individually with sucrase.
This simple workaround won't suit every situation.