简体   繁体   English

在 npm 链接且未编译的一个特定文件夹的 node_modules 中运行 eslint loader

[英]Run eslint loader in node_modules of one particular folder which is npm linked and non compiled one

By using webpack 4 i am able to run eslint across the project folder using this configuration通过使用 webpack 4 我可以使用此配置在项目文件夹中运行 eslint

    {
      enforce: 'pre',
      test: /\.js|ts$/,
      exclude: /node_modules/,
      loader: 'eslint-loader'
    },

Now i want to run eslint in node_modules of one particular folder which is npm linked and non compiled one, for that i used some regular expression like this现在我想在一个特定文件夹的 node_modules 中运行 eslint,该文件夹是 npm 链接和未编译的文件夹,因为我使用了一些像这样的正则表达式

    {
      enforce: 'pre',
      test: /\.js|ts$/,
      exclude: /node_modules\/(?!(my-folder)\/).*/,
      loader: 'eslint-loader'
     },

it didn't worked.它没有用。 suggest me how to achieve this?建议我如何实现这一目标?

I find the following approach works well and is both readable and maintainable我发现以下方法效果很好,既可读又可维护

// webpack.config.js 
module.exports = {
  module: {
    rules: [
      {
        enforce: 'pre',
        test: /\.js|ts$/,
        exclude: /node_modules/,
        loader: 'eslint-loader'
      },
      {
        enforce: 'pre',
        test: /\.js|ts$/,
        include: /node_modules\/my-folder/,
        loader: 'eslint-loader'
      }
    ]
  }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM