vuecli5.x 创建的vue2项目中 如何在运行时候,自动修复eslint报错

项目使用eslint进行代码检查,并在vue.config.js中配置eslint-loader,使其在文件保存时自动执行eslint修复,排除node_modules目录,通过enforce属性设置预加载规则。
摘要由CSDN通过智能技术生成
  1. 因为项目中,使用到了eslint,在项目中单独配置的,不需要依赖vscode等编辑器中安装的插件。在项目中使用eslint,参考添加链接描述
  2. npm install eslint-loader --save-dev
    3.vue.config.js 中进行loader使用配置
  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    name: name,
    resolve: {
      alias: {
        '@': resolve('src')
      }
    },
    // 使用eslint-loader进行文件保存的时候 自动执行eslint修复-->loader写到module中,webpack配置
    module: {
      rules: [
        {
          test: /\.(js|vue)$/, // 匹配的文件来使用该eslint-loader
          exclude: /node_modules/,
          enforce: 'pre', //enforce` 属性表示该规则的执行顺序,`pre` 表示该规则要在其他规则之前执行
          use: [
            {
              loader: 'eslint-loader', // 表示使用哪些 loader 处理匹配到的文件
              options: {
                fix: true, // 开启自动修复
              },
            }
          ]
        }
      ]
    }
  },
  1. 然后重启项目
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值