0

It is possible share my .eslintrc config to be used in other projects?

Below, my webpack.config.js

  mode: 'production',
  module: {
    rules: [
      {
        test: /\.js$/,
        use: {
          loader: 'babel-loader',
          options: {
            babelrc: false,
            cacheDirectory: true,
            plugins: ['transform-react-remove-prop-types'],
            presets: [
              '@babel/preset-react',
              [
                '@babel/preset-env',
                {
                  targets: {
                    esmodules: false
                  }
                }
              ]
            ]
          }
        }
      }
    ]
  },

I'm sharing some Components with other projects, and I likely that this projects would uses my .eslintrc config file.

FabianoLothor
  • 2,752
  • 4
  • 25
  • 39
  • so you have some side project that reuse your component(s). right? how do you see reusing .eslintrc?do you expect it to be applied through all the project's files? what if several dependencies had their own _different_ .eslintrc? – skyboyer Feb 01 '19 at 23:19
  • @skyboyer No, I spect something like that: my ProjectA has a build that contains the `.eslintrc` file, and in my ProjectB, with some way, I want config the `/eslintrc` from the ProjectA in the extends from `eslintConfig` proprety of my `package.json` in ProjectB. Confused? – FabianoLothor Feb 02 '19 at 01:33
  • do you publish ProjectA as a npm package? or you just copy bundled version to ProjectB? – skyboyer Feb 02 '19 at 09:30
  • @skyboyer I am importing a TAG from the ProjectA GIT with the bundle, to the ProjectB – FabianoLothor Feb 02 '19 at 16:19

1 Answers1

0

So I see 2 different questions there:

  1. how to embed .eslintrc into bundle?

    a. how to load .eslintrc? Since it just plain JSON webpack does not need any additional loaders on this move.

    b. how to inject it as a data into bundle? import '../../../.eslintrc'; should help

  2. how to force ESLint using JSON deep inside the bundle? I'm not sure if it's possible at all. extends needs shareable config being published as NPM package. Specifying configuration file by path needs that file to be valid and complete config rather bundle. Configuration reading does not allows any plugins to be connected.

As for me publishing shareable config as npm package and use it in both ProjectA and ProjectB looks much more promising.

skyboyer
  • 22,209
  • 7
  • 57
  • 64
  • The problem with the solution is duplicate equals files. I'm searching some solution to change in one place and share this with other projects, like the airbnb eslint config. – FabianoLothor Feb 03 '19 at 16:11
  • what do you mean under duplicating? after you move shareable config into separate npm package you just add it into both projectA and projectB(`package.json` and eslint's `extends` config section) – skyboyer Feb 03 '19 at 16:17