chore: Add "exports" to package.json #455
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes for #451
The motivation of this change [copied from corresponding pixi.js PR]:
This CR adjusts the package.json to make PIXI easier to use in an ESM environment with TypeScript.
TypeScript 4.7 introduces official (albeit beta) support for ESM in TypeScript. In connection with modern bundling tools such as Vite, it presents an exciting opportunity for front-end development. Unfortunately, the current version of PIXI packages do not behave properly in an ESM environment due to adjustments in how TypeScript resolves packages and types.
To be more specific, when running TS in ESM mode against the current version of PIXI, it resolves the code to the CJS bundle and the types to a non-existent index file in the CJS directory. To get it to correctly resolve both the types and the entrypoint, the package.json needs to include an "exports" key that specifies both types and entrypoint for ESM and CJS.
For more details on this feature, see they TypeScript 4.7 release notes or the node.js documentation. Additionally, for fallback reasons, it's recommend to explicitly include the "types" field which specifies exactly where the types are located in the package.