一個使用vue cli 3.2創建的項目,創建時未開啟 lintOnSave,后來希望開啟並設置為 lintOnSave: 'error',但配置不生效。
解決方法1:新創建項目(此時vue cli 版本為 3.4)並開啟 lintOnSave,然后刪除其中所有文件,將舊有項目所有代碼(包括node_modules)移動到新項目文件夾,發現lintOnSave報錯頁面提示有。
解決方法2:在 vue.config.js 中配置:
module.exports = { devServer: { overlay: { warnings: true, errors: true } }, lintOnSave: 'error', chainWebpack: config => { config.module.rule('eslint').use('eslint-loader').loader('eslint-loader').tap(opt => { opt.emitWarning = opt.emitError = opt.failOnWarning = opt.failOnError = true; return opt; }); } };