-
-
Notifications
You must be signed in to change notification settings - Fork 158
Add option to specify browserslist config file #51
Conversation
Another way I thought this could be fixed was to start at Having a file path as a preset option doesn't seem very elegant to me, but it seems like the only way to make it work every time. |
Sorry will look at this again soon |
8965ab0
to
b3fc3b6
Compare
Haha yeah I was wondering that too..
|
I'l fix the merge conflicts and merge |
Although now not sure how to test with a fixture right.. will postpone for a bit. |
Had a go at adding a fixture for I used |
Allow users of babel-preset-env to specify a path to a `browserslist` file so config can be shared with other tools.
8e347b8
to
6c29e00
Compare
Nice work on the fixture tests! I guess it's interesting that this means if you use a regular |
browserlists has more options that could be useful for us in the future. (ex: stats). |
Yes you're right, I've only really been thinking about the API case, where it's easy to specify an absolute path. If the path were relative where should it be relative to? Relative to the I'm worried that having to specify a path is making this feature feel awkward. Someone who uses browserslist files would naturally assume they can put multiple files and different points in the folder structure, but this makes you choose one config for your project. Which doesn't give much benefit over existing babel-preset-env options. I've been mainly thinking of the CRA case, and as was pointed out in facebook/create-react-app#892 they can just do their own config without a browserslist file. I think what I'm trying to say is I'd rather make a change to babel-core so it gives preset factories the file they're making the preset for so this can be done "right". |
Project's root and node's working directory is often the same, so why not to use process.cwd for making relative (to the root) paths: Maybe there are some pitfalls, but just an option... |
How do other tools that leverage browserslist accomplish this? Ideally, we should just follow that prior art. |
Yeah good idea, from https://github.com/postcss/autoprefixer#browsers
cc @ai |
Having a option with browserslist config is not so clear. It is easy for other developers to miss it. Some other tools (like Stylelint) could miss it too. In Autoprefixer was have no option for config. But I understand that many developers want to have @hzoo when Autoprefixer users ask me about config path option, I told them about BTW, |
Yeah that's what I was thinking - just didn't know how it worked but seems to be the same as .babelrc? |
@hzoo yeap, I like But, maybe we (as community) should support some Developers don’t want to have everything in root file. Having a option is always a bad UX :D. Maybe all tools (PostCSS, Browserslist, Babel) should agree about some config directory? |
That will be a huge change haha, not sure how to convince everyone to do that but we can (outside of this issue though) |
@ai check out this discussion on changing TL; DR: lots of tool devs prefer root (myself included). Not going to really find enough people to agree. |
@hzoo OK, I tried :D. |
I agree with the sentiments here that .babelrc and autoprefixer behaviour are better for users. I also like what @ai said about options 😄. |
Ok yeah maybe we should try finding the browserslist file instead. Would you like to make that pr @p-jackson? What change do we need to do in babel-core? |
I think this is the line that calls the function that generates the preset, and I think the path of the current file being processed should be passed here too. It may be available on the |
I forgot to mention that there is a official way to specify Browserslist config :). BROWSERSLIST_CONFIG=.config/browserslist npm run build I like environment variables because it will be shared in all tasks in current process. |
Also Browserslist 1.5 was released so right now you can specify browsers in {
"private": true,
"dependencies": {
"autoprefixer": "^6.5.4"
},
"browserslist": [
"> 1%",
"last 2 versions"
]
} |
I actually tried to implement it myself before I found this PR. My approach was:
var queryBrowsers = targetOps.browserslist ?
getLowestVersions(browserslist()) :
{};
var browserOpts = targetOps.browsers;
if (isBrowsersQueryValid(browserOpts)) {
Object.assign(queryBrowsers, getLowestVersions(browserslist(browserOpts)))
}
return mergeBrowsers(queryBrowsers, targetOps); This way it seems to be much simpler - babel-preset-env does not take care of internal browserslist behavior of where to get the config from if query is not given. I just wanted to ask you for voicing your opinion on this approach before I prepare a PR: all I have is just working implementation using code above. If you like it I'll prepare a PR. |
@jrencz I think it will be better to have same logic for all frontend tools in |
@ai I'm not sure if I get you correctly. Correct me please if I'm wrong but as far as I can see currently the only way to use browserslist syntax in babel-preset-env is to pass |
@jrencz I don’t use, so I can not be sure :(. But yes, right now |
Is there interest in adding |
@amilajack wow, great to see that eslint-plugin-compat supports Browserslist too :).
|
@amilajack Current discussion: #108. In general, yes. I think we could (and going to) minimize config files for different things to a single line. Node still an issue, but temporary. |
I think a better name, would be Also in this comment, Dan describes using |
@amilajack Autoprefixer, Stylelint and doiuse (eslint-plugin-compat for CSS) works only with
This is a reason why I used |
I see. Also what's the recommended way of importing the user's |
@amilajack why you don't want just use |
@hzoo I've had a trouble getting a PR for babel together that would facilitate this. I've had trouble getting the unit tests to run cleanly (could be because I'm using Bash on Windows). I also struggled understand where the code should go. Is it something to do with the "config chain"? I was able to work it out. The farthest I've got is this commit, but I don't know if it's too naïve, and as I said I couldn't get the tests to work, so haven't submitted it as a PR to babel. But I still think the approach of changing |
Closing in favor of #161 |
Potential fix for #26
The issue talks about using the appropriate browserslist file for each source file. But as was pointed out (and as far as I know) presets can't work in a per-file kind of way.
However the browserslist package also supports specifying a path to the actual config file, which would be enough for something like create-react-app since it knows where the project's root folder is.
I thought it was best to make it an absolute path since this preset could be anywhere compared to the user project's root folder.
Very happy if someone can think of a better name for the option 😄
Let me know if I've misused the
fixtures
folder, or if there's a preferred way to mock the filesystem.