Skip to content
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

Closed
wants to merge 6 commits into from
Closed

Build CJS, update package.json #701

wants to merge 6 commits into from

Conversation

drwpow-figma
Copy link
Contributor

Supercedes #659; just opening for reference

@@ -8,6 +8,24 @@
"main": "dist/a11y-dialog.js",
"module": "dist/a11y-dialog.esm.js",
"types": "dist/a11y-dialog.d.ts",
"exports": {
".": {
Copy link
Contributor Author

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"
},
"./*": "./*"
Copy link
Contributor Author

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'
Copy link
Contributor Author

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',
Copy link
Contributor Author

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,
Copy link
Contributor Author

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.

@KittyGiraudel
Copy link
Owner

Closing in favor of #702. Thank you for the super insightful comments here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants