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

Modern JS #413

Merged
merged 11 commits into from
Jun 14, 2019
Merged

Modern JS #413

merged 11 commits into from
Jun 14, 2019

Conversation

developit
Copy link
Owner

@developit developit commented Jun 10, 2019

This PR adds a new modern value for the -formats/-f option. Modern output uses the target.esmodules setting from @babel/preset-env to compile modern output.

It might be worth exploring targeting something more like "latest". Would love to hear everyone's thoughts!

@developit
Copy link
Owner Author

Failure is upstream, I've opened an issue on babel-plugin-transform-async-to-promises to report the dead Promise.resolve().

@developit developit marked this pull request as ready for review June 11, 2019 05:33
@rpetrich
Copy link
Contributor

rpetrich commented Jun 11, 2019

@developit Give 0.8.12 a go

Copy link
Contributor

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

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

I've been trying out a bunch with the esmodules: true in babel env as well. What I've been thinking is that we're targetting evergreen browsers. These auto-update most of the time shouldn't something like last x versions (targetting canary, stable and version before) be sufficient for something like modern?

@kristoferbaxter
Copy link
Collaborator

@JoviDeCroock – The issue is defining "modern."

The module/nomodule pattern provides the only declarative html driven approach to segmenting functionality. By default module means a lower transpilation ceiling than nomodule, but it's target rapidly decays compared to the next definition of "modern."

We need better signals from user-agents.

@JoviDeCroock
Copy link
Contributor

@kristoferbaxter are you talking about some server that would sniff the user agent and return the correct index.html (with corresponding bundle)?

@kristoferbaxter
Copy link
Collaborator

I'm saying that a more pure declarative signal sent via headers is important. But also, for static documents to be able to leverage via mechanisms similar to declarative html treatments for module/nomodule.

We can only work with what we have available today – so the most modern you can provide in a statically defined way is module/nomodule.

@JoviDeCroock
Copy link
Contributor

Glad to see we're sticking to the syntax.esmodules, built a small webpack plugin when this would go live. 👍 great work @developit really excited about this

@ForsakenHarmony
Copy link
Collaborator

Gotta rebase 👀

Update is already in master

@developit
Copy link
Owner Author

I should have clarified in my PR description: I view target:esmodules as an initial step here, and we'll take another pass at this soon. Once the community has indicated a direction to take for defining modern (or defining syntax levels!) Microbundle will be in a position to output that.

It might be that we decide on "state your syntax and entry", in which case we'd have microbundle generate ES2018 and es5, or steps between the two.

@hbroer
Copy link

hbroer commented Jun 13, 2019

if i don't set this flag, will preset-env respect the browserlist settings in my package.json? Because it also turns on modules (i am 99% sure) if i force modern browsers by their versions. I use edge last 1 version and ff, chrome and safari last 2 versions + mobile equivalents for ios, ff and chrome the most times.

@developit
Copy link
Owner Author

@hbroer esmodules and browserslist can't be used in combination, since esmodules is a effectively "browser list" preset. I believe in the current setup as of this PR, your browserslist in package.json will be applied to the non-modern output, since the modern output is specifically the esmodules preset option.

FWIW it sounds like your browserslist configuration is really really close to target.esmodules, so you might be better off just rolling with the defaults here? Something like microbundle -f modern,umd would produce a modern ES Modules output and an ES5 + UMD fallback, which is sufficient for most packages+bundlers.

@hbroer
Copy link

hbroer commented Jun 14, 2019

My understanding of the flag is that it only turns on modules, but everything which is newer than that feature is transpiled. I really have to take a look into that, because this is only what i think i know with a big question mark above my head ^^

I think this would transpiled to Object.assign() with modules flag on:

{...otherObject, x: "new value"}

And I would expect it doesn't transpile if I set browserlist to chrome and firefox last versions (and nothing else).

@developit
Copy link
Owner Author

@hbroer your understanding is correct. I agree it would be nice to have the modern output format here use a newer syntax mode, but it's hard to make a call on what exactly that cutoff point should be. Lots of folks will want to use the modern version of libraries directly in a browser, which means it's useful to have something like module/nomodule to know when to load the modern syntax.

I think we can improve on this over time, but for now target:esmodules is a pretty safe balance.

@hbroer
Copy link

hbroer commented Jun 14, 2019

Ok sounds fine. Maybe there should be a notice in the readme that it is possible to use browserlist instead of the flag to address browsers directly.

@developit
Copy link
Owner Author

Yup, we can add that - it actually became possible by accident when we switched to Babel last week!

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.

6 participants