-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: dual build to emit both commonJS and ESM to maximize compatibility #31
base: main
Are you sure you want to change the base?
Conversation
"main": "build/lib/es5/index.js", | ||
"module": "build/lib/es6/index.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.
@nthurow These changes make the build come together - commonJS projects will reference "main" whereas ESM projects refer to "module"
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.
But the "module" field isn't official, it's not even really documented anywhere. The "exports" field (along with the "require" and "import" conditions) is the official way to handle a dual build. So that's why what I'm thinking is, can we leave the "main" field here but add back the "exports" field (and make sure to include both "require" and "import" conditions)? The "main" field might solve some of the legacy issues that we are encountering with the SCL and tst-scl, and the "exports" field should still enable the dual-build.
"main": "build/lib/es5/index.js", | ||
"module": "build/lib/es6/index.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.
Can we leave "main"
but remove "module"
? "exports"
is the preferred way to indicate which files can be imported, and "main"
is the legacy fallback option (which is still supported). "module"
was never officially part of the Node/NPM package.json
spec and is just another unofficial field that some bundlers like Webpack recognize.
@@ -0,0 +1,28 @@ | |||
{ | |||
"compilerOptions": { |
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.
Can we use one tsconfig
as the base and have it extend the other?
@NielsJPeschel per our discussion, I opened #32, which should resolve the issues related to certain applications not being able to locate the types for Once that PR is merged we can rebase this one onto |
Proposed changes
Modify
package.json
,tsconfig.json
, as well as createtsconfig.es5.json
to create both an es5 as well as an es6 build. This will simultaneously support CommonJS as well ES modules.Types of changes
What types of changes does your code introduce?
Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.