Is there a way of conditional importing different kind of files depending on the output bundle, if esm or cjs?
For example, I've done a package that uses class-transformer as peer dependency that uses an unexposed API by importing it directly from dist directory, which is a cjs bundle. The issue arises because class-transformer has both cjs and esm builds, so when you use both class-transformer and my package in a esm bundle, my package will always import class-transformer cjs file but class-transformer will uses internally the esm one when is been used. So we can't share the singleton instance that's created inside of the unexposed API.
It can be easily fixed in the webpack config that imports both packages by resolving aliases to a specific class-transformer bundle, the cjs one. But my idea was if maybe in my package I could import the file from dist from a bundle or the other depending on what build target I will be bundling, either esm or cjs.
Is there a way of conditional importing different kind of files depending on the output bundle, if
esmorcjs?For example, I've done a package that uses
class-transformeras peer dependency that uses an unexposed API by importing it directly from dist directory, which is a cjs bundle. The issue arises becauseclass-transformerhas both cjs and esm builds, so when you use bothclass-transformerand my package in a esm bundle, my package will always importclass-transformercjs file butclass-transformerwill uses internally the esm one when is been used. So we can't share the singleton instance that's created inside of the unexposed API.It can be easily fixed in the webpack config that imports both packages by resolving aliases to a specific
class-transformerbundle, the cjs one. But my idea was if maybe in my package I could import the file from dist from a bundle or the other depending on what build target I will be bundling, either esm or cjs.