Skip to content

Add support for ignoring native browserslist resolution#585

Open
apancutt wants to merge 1 commit intoamilajack:mainfrom
apancutt:main
Open

Add support for ignoring native browserslist resolution#585
apancutt wants to merge 1 commit intoamilajack:mainfrom
apancutt:main

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