-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Move "targets"-related options to @babel/core
#2
Move "targets"-related options to @babel/core
#2
Conversation
We created these files as a file-relative config to have a special dir In reality, it is a rare case. At least, minifier should use a project-wide Browserslist in the project root.
I think, that most of the projects should avoid using For the same reason, I think In the end, I think that only |
This is great. At the moment, Parcel has its own wrapper around preset-env: There is another case where we need to create a wrapper for the same reasons: |
FYI related to this proposal is simply the idea we just move |
Potentially we could move the |
I have prepared a PR for this RFC (babel/babel#12189), and made some small updated here with what I found while implementing it. Sorry if I have been super slow (= 6 months? 😅) to reply to the comments.
This will likely be fixed by using "exports": {
"./helpers/foo": {
"import": "./helpers/esm/foo.js",
"default": "./helpers/foo.js"
}
}
That is one of my end goals, but I want to that slowly to use this opportunity to also improve the general API. This RFC and #5 both move in that direction. |
rfcs/0000-top-level-browserslist.md
Outdated
|
||
## New Babel options | ||
|
||
### `targets` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should "targets"
be merged? It seems that [].concat
(like how we did for presets
) suffices but we should document about that as it may be out of expectation:
If babel-preset-esmodule
specifies targets: "chrome 52, safari 14.1, node 13.2"
and babel-preset-node
specifies targets: node >= 8
, the resolved targets
will be ["chrome 52, safari 14.1, node 13.2", "node >= 8"]
, which is the union of these two targets
.
But when targets
is an object, our config merging (by default) will make intersect these two targets. We should specialize the merging of targets
.
{
chrome: 52,
safari: "14.1",
node: "13.2"
} + { node: "14.0" }
== {
chrome: 52,
safari: "14.1",
node: "14.0"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another edge case for merging targets is that, what if some plugin specifies the target
as an array whereas another plugin supplies target
as an object or a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
targets
are only allowed in user config files, not in presets: presets need to be targets
consumers.
For this reason, I tried thinking what conflicting targets could be caused from, and the most common use cases would be to have an env
block that defines another set of targets for modern/legacy browsers.
For this reason, I think that replacing targets is what makes most sense: then both of these work:
{
"targets": "> ie 10",
"presets": ["@babel/env"],
"env": {
"modern": {
"targets": { "esmodules": true }
}
}
}
{
"targets": { "esmodules": true },
"presets": ["@babel/env"],
"env": {
"legacy": {
"targets": "> ie 10"
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added these examples to the RFC body
What should be the behavior of
I think that "explicit browser versions win" is a good rule so that you can explicitly overwrite specific browsers in the browserslist/ However, I'm not sure about why What if we computed the intersection of
The main downside I see is that if someone uses a {
"targets": { "esmodules": true }
} because we are still loading and intersecting the {
"browserslistConfigFile": false,
"targets": { "esmodules": true }
} However I'm note sure about why someone would want to support targets older than what they have in their |
Regarding my previous comment about the
That is: by default (at least, the default behavior we provide) it computes the union of the targets, and you can specify Given that:
For people currently relying on it, it's a very simple change: - targets: {
- esmodules: true
- }
+ targets: "supports es6-module" Thoughts? |
Idea: if it's true that there are common browserslist queries that are more modern than I'm still seeing the overwhelming majority of configurations specify a browserslist query that includes IE11, generally the default query of
|
After further discussion with @developit, we came to the conclusion that the When using the Making it intersect the Browserslist targets rather than replacing them fixes the problem of described at babel/babel#8809. |
Making my way here from the trail of reading new features. Love the unified options. I see in the RFC the preset case with defined targets is brought up but doesn't really come to a good workaround? I don't think most instances of this issue are like CRA where the tool owns the entire build pipeline. For instance, we make heavy use of custom presets to enforce correct target configurations at our company. Providing a |
Would something like https://babeljs.io/docs/en/options#extends work for you? The company provides a common config, and specific projects can extend it to add other plugins/presets. |
I guess the problem there is it's not easily parametrized, and relying on preset, plugin merging would be too coarse i think. That configs can be JS files means we could build some sort of config generator but that seems less than ideal, and doesn't compose nicely with the rest of ecosystem. |
View Rendered Text
This RFC proposes moving the Browserslist integration from
@babel/preset-env
to@babel/core
. This means deprecating all the Browserslists-related option from the preset and introducing new top-level configuration options.PR: babel/babel#12189
This is the first time we test the new "standardized" RFC process, let's hope that it works 🤞
I'm pinging a few people who might be interested in this:
Please share this RFC with anyone who can contribute to the discussion!