mattdesl / mattdesl/esmify

default export should behave differently when it's the only export

Open
#12 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
119
Forks
11
PR merge metrics
No merged PRs in 30d

Description

When I don't use esmify and I write
```
module.exports = () => { ... }
```
and I build it like
```
browserify source.js -o dist.js -s "foo"
```

I can just write `foo()` and my function will be executed. However, when I use esmify and I write
```
export default () => {}
```
and build it the same way, `foo` actually represents an object that contains `default` property, so if I want to call it, I should write
```
foo.default()
```

I think that if there is a default export and there are no more exports, that exported value should be set to `window.foo` instead of an object.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how esmify represents an `export default` when browserify builds a bundle with `-s`. Compare that result with the CommonJS `module.exports` case shown in the issue; done means a module containing only a default export exposes the value directly as `window.foo`, while modules with additional exports retain an object shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.