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

feat: Support customizing the modern output via "exports" #784

Merged
merged 4 commits into from
Jun 3, 2021
Merged

feat: Support customizing the modern output via "exports" #784

merged 4 commits into from
Jun 3, 2021

Conversation

rschristian
Copy link
Collaborator

Summary

Closes #783

Allows users to customize modern output file name with exports like they can with esmodules.

@changeset-bot
Copy link

changeset-bot bot commented Jan 7, 2021

🦋 Changeset detected

Latest commit: 3ccfefd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
microbundle Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

src/index.js Show resolved Hide resolved
src/index.js Outdated
@@ -280,7 +280,10 @@ function getMain({ options, entry, format }) {
mainNoExtension,
);
mainsByFormat.modern = replaceName(
(pkg.syntax && pkg.syntax.esmodules) || pkg.esmodule || 'x.modern.js',
(typeof pkg.exports === 'string' && pkg.exports) ||
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for the main case. I'm wondering - maybe we could walk the exports object to find matching import entries?

function walk(exports) {
  if (typeof exports === 'string') return exports;
  return walk(exports['.'] || exports.import || exports.module);
}

walk(pkg.exports)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly could. I started to think about this but had reservations on whether or not users would expect all keys (or at least the ones in the spec?) to be supported. If they have a "require", would they then expect a matching output file? Not sure.

@developit developit merged commit 86371f0 into developit:master Jun 3, 2021
@preact-bot preact-bot mentioned this pull request Jun 3, 2021
@rschristian rschristian deleted the feat/modernFileName branch June 8, 2021 01:23
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.

Feature: Customize modern output file name using the "exports" field
2 participants