Conversation
b2c6cb1 to
962b626
Compare
Current coverage is
|
|
Would be super nice if it could just adhere to what's in the |
|
@sindresorhus is that only for node? Could def work as a default if it's there. |
|
@hzoo Only for Node.js yes. |
|
I'd like to chime in here as I was planning to implement this feature until I noticed this issue. I've pretty much got it all planned out, just need to actually build it. Basically it would go:
Based on the following links:
When babel is ran, it would work similar to autoprefixer, in which you can target individual browser versions, or you can do "last 3 versions", etc. It would then validate the browser version in each package, and determine whether to run the transformer or not. If a browser version is
We also have kangax and caniuse.
I would really love this feature, as I currently work on internal tools at my company, in which we only have to support Chrome 40+. This feature would lower our filesize and tech debt considerably. This will be especially important since V8 has almost 100% ES2015 support: http://v8project.blogspot.se/2016/04/v8-release-51.html |
|
node.green also has tons of info. |
|
As a node module author who wants to write for node 5 but has to support |
|
It might be worth adding a the ability to just set Most browsers are evergreen now, so depending on your customer base, adding support for anything more than latest may just be a matter of allowing people a little time to get the latest update (I realise this may be different in the corporate world or other demographics). Overall I think this feature will be great, it'll cut down on the size of exported code and will make pages more performant (no feature detection in some cases, less polyfills). |
|
@mrmckeb for sure that would be a useful feature (given this is basically autoprefixer for babel), just need to update when new browsers come out |
|
What about using https://github.com/ai/browserslist instead of specifying each browser version? |
|
Yeah that sounds great - cc @ai if you have any tips or can help with this effort |
|
@hzoo sure, Autoprefixer, cssnext and Babel will take same browsers from |
|
Yeah Babel is a bit different since we will also need other js environments like node, electron, etc. I think we can start with browsers as a proof of concept though since not sure how we want to do it. |
|
I could add Electron and other env’s support to browserslist. |
|
Good thing you guys pinged this as I was itching to try it out. Has any work been done on this yet (besides this PR)? |
|
Not that I know of? If anyone knows about anything please send a link (if it makes it easier to contribute we can move this to another repo and then merge it in afterwards) Sorry, was busy doing other stuff (also merge preset options so this will actually work) but would like to start if we have a better idea of how it will work - it sounds like we can break it down into
Other Features
|
|
I built something like this with auto-babel. It's currently working for node, and I had previously used sauce labs to run tests for browser support. I haven't updated it to work with babel 6 yet. I found the kangax raw data unsuitable for browserslist matching and caniuse missing JS feature support completely. |
|
https://github.com/kangax/compat-table doesn't have raw data yet. There is an issue compat-table/compat-table#785 |
|
Probably better as a separate repo, so moving to https://github.com/babel/babel-preset-env |
|
I just stumbled across this post. I've also been working on a preset with this support. |
| let loose = false; | ||
| let modules = true; | ||
| if (opts !== undefined){ | ||
| >>>>>>> 56a3ede... babel-preset-env:packages/babel-preset-es2015/index.js |
|
Ok actually moving this PR to https://github.com/babel/babel-preset-env (when it's more stable we can add it back). Will need to transfer the comments we have here over there (and if anyone wants to add issues feel free) Sounds like it would be good to combine efforts with @jakepusateri's https://github.com/jakepusateri/auto-babel that has auto node support and @sdkennedy's work on https://github.com/sdkennedy/babel-preset-target |
|
So https://github.com/babel/babel-preset-env has a basic implementation now - 0.0.1. Data is probably wrong but that can always be updated |
|
@hzoo This rocks, I used to use both babel-preset-modern-browsers and babel-preset-modern-node and it looks like this could replace both. Thanks! |
|
We'd appreciate the help on preset-env to make it more robust but of course feel free to continue working on other presets as well! Hopefully we can work together on this since there seems to be a lot of edge cases to handle |
|
|
|
Just FYI https://github.com/babel/babel-preset-env is 1.0 now! Has a lot of new stuff
|
Moved to https://github.com/babel/babel-preset-env
Mostly for a discussion (no implementation atm)
Basic idea to be able to specify an environment/s so that babel wouldn't transform what is already implemented natively.
This can be useful given that the latest browsers/node have implemented a good amount of es2015 already unlike a few years ago, and there are currently numerous presets for each environment (babel-preset-node5, babel-preset-modern, etc). We are at the point where you might not need the es2015 preset at all (and we would like to see an automated solution).
TL;DR
Also this isn't about dynamically doing this at runtime but just a similar configuration where an environment is mapped to a set of plugins beforehand.
EDIT: Another recent discussion https://gist.github.com/addyosmani/bb6e2939f943226e68e87396c4931040
Previous Discussions:
babel-plugin-transform-runtimeor polyfill based on environment.Some other articles
How do we get the data?
Many people will probably think of using something like https://github.com/kangax/compat-table/. This would be great will we could use these resources and just create a mapping to transforms. Looking at https://github.com/Fyrd/caniuse it looks like it defers to kangax's table for es2015.
It could just be a list and we update it when necessary (with community input/help).
How do you specify this in Babel?
Targets
Could be a builtin config value like
targets/environments:Like what buble is doing: https://gitlab.com/Rich-Harris/buble/blob/master/src/support.js
Targets would specify plugins that are implemented already and could act like a blacklist against the plugins passed in.
Preset (most likely option)
This would depend on something like logan's pr: #3331 which allows passing options to presets.
Even if this isn't a builtin feature like a targets key in
.babelrc, it could at least be a preset with options that allow you to specify the environments you support.We don't have to do this only for es2015 since some stage-x features are also in development. Could do another option if users want to test in a browser that has a feature behind a flag.
Other?