Add modularized imports to the exports field
prichodko opened this issue · comments
I was trying to make @phosphor-icons/react
work with the new modularized imports feature in Next.js.
It should:
- Improve the bundle size
- Increase compilation speed thanks to skipping unused files.
I tried adding this configuration to my next.config.js
:
const config = {
// ...
modularizeImports: {
'@phosphor-icons/react': {
transform: '@phosphor-icons/react/dist/icons/{{member}}',
},
},
// ...
}
Unfortunately, it fails with the following error:
Error: Package subpath './Trash' is not defined by "exports" in /Users/[REDACTED]/node_modules/@phosphor-icons/react/package.json
I was reading through @phosphor-icons/react
package.json files and saw that that exports
field only allows root import. Adding a new subpath fixed the issue:
{
"exports": {
".": {
"import": "./dist/index.es.js"
},
"./*": {
"import": "./dist/icons/*.es.js"
}
},
}
I suggest adding this path to the exports
field to allow users opt-in to the modularized imports if they want. I believe it's generally a good practice to allow this.
Happy to send a PR @rektdeckard. 👍
Thanks for this @prichodko. Already in flight!