eslint webpack 配置笔记

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/oYuLian/article/details/89466365

安装依赖
npm install --D eslint
npm install --D eslint-loader

2.在最外面添加.eslintrc.js 文件
module.exports = {
    root: true,    
    parserOptions: {
        ecmaVersion: 7,//表示使用es2016
        sourceType: 'module'//指定模块类型sourceType为module
    },
    env: {
        browser: true,
    },
    rules: {
        "indent": ["error", 2],
        "quotes": ["error", "double"],
        "semi": ["error", "always"],
        "no-console": "error",
        "arrow-parens": 0
    }
}

3.在webpack 下增加loader
 module: {
 rules: [
 {
      test: /\.js$/,
      loader: 'eslint-loader',
      enforce: "pre",
      include: [path.resolve(__dirname, '../src')], // 指定检查的目录
      options: { // 这里的配置项参数将会被传递到 eslint 的 CLIEngine 
        //formatter: require('eslint-friendly-formatter') // 指定错误报告的格式规范
      }
    }
 ]
 }


4.万能方法,就是在报错的JS文件中第一行写上 
/* eslint-disable */

猜你喜欢

转载自blog.csdn.net/oYuLian/article/details/89466365