Skip to content
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

Allow multiple browserlist environments #392

Closed
iFarmGolems opened this issue Aug 13, 2020 · 5 comments · Fixed by #587
Closed

Allow multiple browserlist environments #392

iFarmGolems opened this issue Aug 13, 2020 · 5 comments · Fixed by #587

Comments

@iFarmGolems
Copy link

Hey, not sure if feature is present or not but I don't see anything in documentation about multiple browserlist environments

Would it be possible to add support for this / is it present somehow ?

Thanks.

@amilajack
Copy link
Owner

I think we do support multiple environments but I'll have to check. Are there any issues you're running into because of this?

@semiaddict
Copy link

Hi,
I also needed support for multiple browserlist environments.
I am using Babel with Webpack 5 with multiple webpack configs to target different browsers per entry (part of the code needs to run on legacy browsers, while another part only needs to run on modern browsers).

It took me a while to figure out how to specify a different browserslist environment for each config, and ended up with something along the lines of:

const browserslist = require('browserslist');
const env = 'legacy'; // The browserslist environment id
const browsers = browserslist.findConfig('./')[env]; // Loads the browserslist environment

.....
new ESLintPlugin({
  failOnError: false,
  overrideConfig: {
    rules: {
      "compat/compat": ["error", browsers.join(",")],
    }
  }
})
.....

This seems to work fine. So it might be helpful to document the fact that the plugin can take a string browserslist config as an option to the eslint rule.

@frehner
Copy link
Contributor

frehner commented Jul 6, 2023

I believe this line creates the options for browserslist and then is passed to browserslist() here later, so it appears that currently there isn't an easy way to set the env for browserslist, so it defaults to production.

That helper gets called from the rule here.

@amilajack Would you be open to me creating a new PR adding something like settings.browserslistOpts to your eslint config, and then reading it in and passing it to that function?

@amilajack
Copy link
Owner

Thanks for outlining that. A pr would be great!

@muuvmuuv
Copy link

muuvmuuv commented Jul 19, 2023

Stumbled on this as well. We have two sets, but I don't get reports for Array.prototype.at (which is only available upon Chrome Android 92):

  "browserslist": {
    "production": [
      "last 10 Chrome versions",
      "last 20 ChromeAndroid versions",
      "last 5 Safari versions",
      "last 3 iOS versions",
      "last 10 Firefox versions",
      "last 10 FirefoxAndroid versions",
      "last 5 Edge versions",
      "Firefox ESR",
      "not dead",
      "> 10% in DE"
    ],
    "mobile": [
      "iOS >= 13",
      "Android >= 9",
      "Chrome >= 66"
    ]
  },

Would be great if it would respect both or if I could define which I prefer during development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants