-1

I need to some how create an ESLint configuration that works for both Vue 2 and Vue 3, to be able to use it across multiple projects (by installing it as an NPM package).

I tried to use vue-demi to detect the Vue version and then switch things out in the .eslintrc file, but it doesn't seem to be working.

Does anyone know of a way to achieve this? Would really appreciate the help!

Kris D. J.
  • 612
  • 2
  • 7
  • 16
  • You can just read vue version from package.json and conditionally add plugins to `extends` section in eslint config – Estus Flask Mar 11 '23 at 23:08
  • @EstusFlask How do I read the Vue version? – Kris D. J. Mar 12 '23 at 05:57
  • Something like `let package = require('./package.json'); let vueVer = Object.entries(package.dependencies).find(([k]) => k === 'vue')[1]; let isVue2 = semver.satisfies('2', vueVer)`. Where semver is semver package or any other semver parser – Estus Flask Mar 12 '23 at 08:15

1 Answers1

0

You can use different majors of the package for different majors of Vue. Let's say your package is awesome-eslint-plugin.

The project's .eslintrc.yml would look like this, regardless of Vue version:

root: true
extends:
 - 'plugin:awesome-eslint-plugin'

In Vue2 projects install awesome-eslint-plugin@^2.
In Vue3 projects install awesome-eslint-plugin@^3.

Or @latest and @next.

tao
  • 82,996
  • 16
  • 114
  • 150