Skip to content

Commit

Permalink
feat: Support customizing the modern output via "exports" (#784)
Browse files Browse the repository at this point in the history
* feat: Support customizing the modern output via "exports"

* docs: Adding changeset

* refactor: Further support "modern" output name with exports object

Co-authored-by: Jason Miller <developit@users.noreply.github.com>

* fix: Correcting odd typo

Co-authored-by: Jason Miller <developit@users.noreply.github.com>
  • Loading branch information
rschristian and developit committed Jun 3, 2021
1 parent 2b37c12 commit 86371f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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 @@ -256,6 +256,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 @@ -287,7 +292,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(
Expand Down

0 comments on commit 86371f0

Please sign in to comment.