New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add exports field to package.json #659
base: main
Are you sure you want to change the base?
Conversation
@@ -8,6 +8,21 @@ | |||
"main": "dist/a11y-dialog.js", | |||
"module": "dist/a11y-dialog.esm.js", | |||
"types": "dist/a11y-dialog.d.ts", | |||
"exports": { | |||
".": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you do import A11yDialog from 'a11y-dialog'
you get ./dist/a11y-dialog.esm.js
, and when you do const A11yDialog = require('a11y-dialog)
you get ./dist/a11y-dialog.js
"dist/*.esm.js": "./dist/*.esm.js", | ||
"dist/*.js": "./dist/*.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone is importing using an exact extension, give them what they asked for
"dist/*": { | ||
"import": "./dist/*.esm.js", | ||
"require": "./dist/*.js", | ||
"types": "./dist/*.d.ts" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise if the extension is omitted, use the appropriate extension depending on import or require
"require": "./dist/*.js", | ||
"types": "./dist/*.d.ts" | ||
}, | ||
"package.json": "./package.json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
general best practice to allow importing your package.json
Thank you so much for the PR and the explanations! Do you think we should do that in v9 or is it safe to ship as is? Is there any import that could potentially break when setting this up? |
fixes #646
Left some inline comments on what each part is for. Mostly I'm being defensive, so that if any of these import patterns are already in use, they'll still work and this can be a minor version bump.
I'd recommend at some point locking this down to just the
.
and thepackage.json
entries and making that a major version bump.