-
Notifications
You must be signed in to change notification settings - Fork 130
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
Build CJS, update package.json #701
Conversation
@@ -8,6 +8,24 @@ | |||
"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.
As discussed elsewhere, I guess the "."
character is optional; I’m just used to seeing this syntax more. Probably doesn’t matter.
"require": "./dist/a11y-dialog.cjs", | ||
"types": "./dist/a11y-dialog.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.
I like doing this: just exposing all files by default, as-typed. This is safer than having to manually type out every file one-by-one (and newer files don’t get exposed if they’re not typed out).
IMO trying to be clever, and trying to anticipate how people have manually-imported specific files from /dist/
, can backfire unless you’ve tested every possible setup. Instead, I like to trust that users do the right thing, and if they’re manually importing a file, just let them.
import { nodeResolve } from '@rollup/plugin-node-resolve' | ||
import terser from '@rollup/plugin-terser' |
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.
This got formatted by the githook IDK
plugins: plugins, | ||
output: [ | ||
{ | ||
file: 'dist/a11y-dialog.cjs', |
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.
New file for Node.js that doesn’t change contents of previous files.
@@ -55,6 +55,16 @@ export default [ | |||
}, | |||
], | |||
}, | |||
{ | |||
input: 'src/index.ts', | |||
plugins: plugins, |
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.
Note: I believe it’s generating the correct thing using the existing tsconfig.json
. But best practice is to make a 2nd TS Config (e.g. tsconfig.cjs.json
) if it stops working as-expected (worth noting that the current TSConfig uses legacy module resolution, so you may have to split it up if you used "module": "ESNext", "moduleResolution": "Bundler":
which is now the recommended setup for most frontend code.
Closing in favor of #702. Thank you for the super insightful comments here! |
Supercedes #659; just opening for reference