eslint 设置 warning 级别,在 开发编译失败的原因,报错如下:
F:\vue-mobile-skeleton>npm run dev
> [email protected] dev F:\vue-mobile-skeleton
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
94% asset optimization
ERROR Failed to compile with 1 errors 22:51:17
error in ./src/app.vue
Module build failed: Module failed because of a eslint warning.
⚠ http://eslint.org/docs/rules/no-unused-vars 'o' is assigned a value but never used
src\app.vue:60:7
const o = 90;
^
✘ 1 problem (0 errors, 1 warning)
Warnings:
1 http://eslint.org/docs/rules/no-unused-vars
@ ./src/main.js 12:0-28
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
Module build failed: Module failed because of a eslint warning的原因,为自己当时即使是eslint 设置 warning 规则,在热更新都会报错,无法编译通过的!
解决:
1:把这个没有使用变量,删除
2:使用 注释方式不进行检测 => // eslint-disable-next-line
3:把 eslint-laoder 的选项设置 fasle 即可;
// 目录:/build/webpack.base.conf.js const createLintingRule = () => ({ test: /\.(js|vue)$/, loader: 'eslint-loader', enforce: 'pre', include: [resolve('src'), resolve('test')], options: { formatter: require('eslint-friendly-formatter'), emitError:false, emitWarning: config.dev.showEslintErrorsInOverlay, fix: true, failOnError: true, //如果有eslint警告,加载器将导致模块构建失败。 //设置 false 即可,去除此检验 failOnWarning: false, } })
但是,还是看个人喜好,若是单单在控制台提示警告也可以,不过我本人不想看到有警告,所以就硬性设为 true 不让编译通过,个人喜爱而已!