Background: I am migrating an app which was using babel for transpilation and outputting to a directory like lib. Users would then import by a fully qualified path, such as: import Button from "@org/library/lib/components/button"
I transitioned to vite and was able to get it building in a way that matches up with babel transpilation, but the problem is, it will output both a .cjs file and a .mjs file (for ESM and CJS). I tried to add this to the package.json like this:
"exports": {
"./package.json": "./package.json",
"./*": {
"import": "./*.mjs",
"types": "./*.d.ts",
"require": "./*.cjs"
}
}
However, this doesn't seem to map. When I build my project and distribute it, it is throwing an error for imports like @org/my-library/lib/components/button
As a fallback, I am able to delete the exports field and distribute it and it seems to build appropriately, but I'm not entirely sure if it's picking up CJS or ESM formats for the distributables, which seems important
Is there a way to do this in a package.json?