vue-cli5创建的vue项目,自动修复eslint错误(配置vue.config.js,无需vscode插件)
找到vue.config.js,直接上代码:
方便大家复制粘贴:
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
lintOnSave:true,
chainWebpack: config => {
config
.plugin('eslint')
.tap(args => {
args[0].fix = true
return args
})
}
})
一开始用的是:
结果一顿报错,查了一天,就在我崩溃之际,突然发现:
eslint-loader被弃用了!!我更崩溃了。。。
现在官方推荐使用eslint-webpack-plugin,用法链接:eslint-webpack-plugin使用方法(官方文档)
但是vue-cli5里内置了这个插件,你只需要在vue.config.js里配置一下就可以了。
ok,到此结束。