Adds browsers property to use browserslist's queries#19
Conversation
browsers property to use browserslist's queries
|
awesome! If you can make test for this as well with a few cases that would be great |
package.json
Outdated
| "babel-plugin-transform-flow-strip-types": "^6.8.0", | ||
| "babel-preset-es2015": "^6.14.0", | ||
| "babel-register": "^6.14.0", | ||
| "browserslist": "^1.4.0", |
There was a problem hiding this comment.
This will have to be a dependency if we are using it in src
There was a problem hiding this comment.
Although it would be better if it was used as a devDependency
src/index.js
Outdated
| const getTargets = targetOpts => { | ||
| return targetOpts || {}; | ||
| const mergedOpts = targetOpts || {}; | ||
| const browserOpts = targetOpts['browsers']; |
There was a problem hiding this comment.
Do we want to do any validation here? (like in loose/modules we verify if boolean etc)
|
I think, browsers defined in targets' root must have higher priority than items we receiving in browsers query. {
targets: {
chrome: 50,
safari: 10,
browsers: ['last 2 chrome versions', 'last 2 safari versions'] // chrome 52, safari 9
}
}will output |
|
Yep I think so to, we should update the doc/comment to say that explicit targets will override what's in browsers |
src/index.js
Outdated
| } else { | ||
| mergedOpts = targetOpts; | ||
| } | ||
| return mergedOpts; |
There was a problem hiding this comment.
You could also do an early return here
const browserOpts = targetOpts.browsers;
if (isBrowsersQueryValid(browserOpts)) {
const queryBrowsers = getLowestVersions(browserslist(browserOpts));
return mergeBrowsers(queryBrowsers, targetOpts);
}
return targetOps;| * @return {Boolean} Whether or not the transformation is required | ||
| */ | ||
| export const isPluginRequired = (supportedEnvironments, plugin) => { | ||
| if (supportedEnvironments.browsers) { |
There was a problem hiding this comment.
Is this necessary?
The code that calls this does
const targets = getTargets(opts.targets);
isPluginRequired(targets, pluginList[pluginName]));
There was a problem hiding this comment.
@hzoo It's just for usage from a separate module. When options are not handled yet.
There was a problem hiding this comment.
I left it in buildPreset to prevent running getTargets method for each item from pluginList
|
Ok great, looks good!! 🎉 |
|
Do we really need possibility to mention browsers directly in targets? AFAIK browserlist can handle this. Result of is equal to result of Example: http://browserl.ist/?q=last+2+versions%2C+not+ie+%3C+11%2C+chrome+5 |
|
I guess it depends on what browserlist supports compared to the compat-table - yeah node? |
|
It looks like autoprefixer is now recommending a browserlist file in the project root rather than configure tools directly. Does this support that? |
|
Nope it's just a string atm - there #26 open though! |
|
gotcha. thanks @hzoo! |
This PR allows us to use browsers property with query like autoprefixer does.
For example, babelrc:
will include chrome 52 and safari 8, 9, 10.
ios_saf, ie11 and others unsupported browsers will be ignored.