-
-
Notifications
You must be signed in to change notification settings - Fork 158
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 |
@@ -52,6 +52,7 @@ | |||
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will have to be a dependency if we are using it in src
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.
Although it would be better if it was used as a devDependency
@@ -62,7 +63,16 @@ export const isPluginRequired = (supportedEnvironments, plugin) => { | |||
}; | |||
|
|||
const getTargets = targetOpts => { | |||
return targetOpts || {}; | |||
const mergedOpts = targetOpts || {}; | |||
const browserOpts = targetOpts['browsers']; |
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.
Do we want to do any validation here? (like in loose/modules we verify if boolean etc)
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.
Oh I see it's ignored right below
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 |
} else { | ||
mergedOpts = targetOpts; | ||
} | ||
return mergedOpts; |
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.
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;
@@ -39,6 +40,10 @@ export const MODULE_TRANSFORMATIONS = { | |||
* @return {Boolean} Whether or not the transformation is required | |||
*/ | |||
export const isPluginRequired = (supportedEnvironments, plugin) => { | |||
if (supportedEnvironments.browsers) { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hzoo It's just for usage from a separate module. When options are not handled yet.
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 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.