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

Add support for ignoring native browserslist resolution #585

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

apancutt
Copy link

Fixes #411

Consider a scenario where a project contains code destined for NodeJS except for the src directory which is for browsers. The project has the following browserslist config:

{
  browserslist: {
    production: ["defaults"],
    node: ["node 18"],
  },
}

We want compat/compat to use the "node" env for everything except the src directory, and "production" (browserslist default env) within src. This is currently not possible since additional targets are always merged with browserslist-resolved targets (when config is present).

This change adds support for a new options structure (with full BC):

{
  rules: {
    "compat/compat": ["error", {
      ignoreBrowserslistTargets?: boolean; (default: false)
      query: string | string[];
    } ],
  },
}

Setting ignoreBrowserslistTargets: true will prevent merging targets provided in query with the ones resolved by browserslist.

We can now do something like this:

{
  rules: {
    "compat/compat": ["error", {
      ignoreBrowserslistTargets: true,
      query: require('browserslist').findConfig(__dirname).node,
    }],
  },
  overrides: [
    {
      files: ["src/"],
      rules: {
        "compat/compat": "error"
      },
    },
  ],
}

The targets defined in the "node" browserslist environment will now be used everywhere in the project except within the src directory where the "production" environment will be used instead.

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

Successfully merging this pull request may close these issues.

disable merging of eslintrc browserslist config
1 participant