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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tender-pants-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'microbundle': patch
---

Allows users to customize the modern output's filename using "exports" like they can with "esmodules"
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ function replaceName(filename, name) {
);
}

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

function getMain({ options, entry, format }) {
const { pkg } = options;
const pkgMain = options['pkg-main'];
Expand Down Expand Up @@ -280,7 +285,10 @@ function getMain({ options, entry, format }) {
mainNoExtension,
);
mainsByFormat.modern = replaceName(
(pkg.syntax && pkg.syntax.esmodules) || pkg.esmodule || 'x.modern.js',
(pkg.exports && walk(pkg.exports)) ||
(pkg.syntax && pkg.syntax.esmodules) ||
pkg.esmodule ||
'x.modern.js',
mainNoExtension,
);
mainsByFormat.cjs = replaceName(pkg['cjs:main'] || 'x.js', mainNoExtension);
Expand Down