Skip to content

Commit 86371f0

Browse files
feat: Support customizing the modern output via "exports" (#784)
* 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>
1 parent 2b37c12 commit 86371f0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.changeset/tender-pants-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'microbundle': patch
3+
---
4+
5+
Allows users to customize the modern output's filename using "exports" like they can with "esmodules"

src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ function replaceName(filename, name) {
256256
);
257257
}
258258

259+
function walk(exports) {
260+
if (typeof exports === 'string') return exports;
261+
return walk(exports['.'] || exports.import || exports.module);
262+
}
263+
259264
function getMain({ options, entry, format }) {
260265
const { pkg } = options;
261266
const pkgMain = options['pkg-main'];
@@ -287,7 +292,10 @@ function getMain({ options, entry, format }) {
287292
mainNoExtension,
288293
);
289294
mainsByFormat.modern = replaceName(
290-
(pkg.syntax && pkg.syntax.esmodules) || pkg.esmodule || 'x.modern.js',
295+
(pkg.exports && walk(pkg.exports)) ||
296+
(pkg.syntax && pkg.syntax.esmodules) ||
297+
pkg.esmodule ||
298+
'x.modern.js',
291299
mainNoExtension,
292300
);
293301
mainsByFormat.cjs = replaceName(

0 commit comments

Comments
 (0)