关闭保存时自动代码检测
1. vue.config.js中
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
lintOnSave: false, // 关闭保存时自动代码检测
})
2. .eslintrc.js
module.exports = {
root: true,
env: {
browser: true,
node: true,
},
parserOptions: {
ecmaVersion: 2018, // 或者你想要支持的更高版本
sourceType: 'module', // 如果是模块化代码,请包含此选项
},
extends: [],
rules: {}, // 清空所有规则或设置为空对象来禁用所有规则
};
代码全局格式化
package.json中
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.vue\"" // ts 代码全局格式化
// "format": "prettier --write \"src/**/*.js\" \"src/**/*.vue\"" // js 代码全局格式化
"format-changed": "powershell -Command \"$files = git diff --name-only --diff-filter=ACMRTUXB HEAD~1 src/**/*.js src/**/*.vue; $files | ForEach-Object { prettier --write $_ }\"" // 仅格式化改动的文件
},
运行方式: npm run format