- 因为项目中,使用到了eslint,在项目中单独配置的,不需要依赖vscode等编辑器中安装的插件。在项目中使用eslint,参考添加链接描述
- 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, // 开启自动修复
},
}
]
}
]
}
},
- 然后重启项目