当前位置: 首页 > news >正文

VUE3项目学习系列--项目配置(二)

        在项目团队开发过程中,多人协同开发为保证项目格式书写格式统一标准化,因此需要进行代码格式化校验,包括在代码编写过程中以及代码提交前进行自动格式化,因此需要进行在项目中进行相关的配置使之代码格式一致。 

一、eslint配置

eslint是提供一个插件化的javascript代码检测工具。

安装eslint

pnpm i eslint -D

生成配置文件,执行如下命令后自动生成对应的配置文件:eslint.cjs

 nps eslint --init

执行命令后根据提示选择如下配置完成文件生成 

添加eslint校验规则

module.exports = {// 环境配置"env": {"browser": true,//浏览器运行"es2021": true},// 规则继承"extends": [// 全部规则默认是关闭的,该配置会开启推荐规则,按照文档进行配置"eslint:recommended","plugin:@typescript-eslint/recommended","plugin:vue/vue3-essential"],"overrides": [{"env": {"node": true},"files": [".eslintrc.{js,cjs}"],"parserOptions": {"sourceType": "script"}}],"parserOptions": {"ecmaVersion": "latest","parser": "@typescript-eslint/parser","sourceType": "module"},"plugins": ["@typescript-eslint","vue"],// eslint 规则"rules": {'no-var': 'error',  // 禁止var'no-multiple-empty-lines': ['warn', {max: 1}], // 不允许多个空行'no-useless-escape': 'off', // 关闭禁止不必要的转义字符// typeScript'@typescript-eslint/no-unused-vars': 'error','@typescript-eslint/no-explicit-any': 'off',// eslint-plugin-vue'vue/multi-word-component-names': 'off',  // 关闭名称只能-连接'vue/no-mutating-props': 'off',  // 关闭组件prop不能改变'vue/attribute-hyphenation': 'off', // 关闭对模板中自定义组件强制执行属性命名样式}
}

添加忽略校验文件配置,创建文件:.eslintignore 

dist
node_modeules

添加运行脚本

在package.json 中新增运行脚本

  "scripts": {"lint": "eslint src","fix": "eslint src --fix"},

 二、配置prettier

eslint是针对javascript进行语法检测,保证程序的准确运行,preitter是对代码格式进行统一格式化的工具,保证项目格式一致美观;

1、安装依赖包

 pnpm install -D eslint-plugin-prettier prettier eslint-config-prettier

2、添加.preitterc.json文件

{"singleQuote": true,"semi": false,"bracketSpacing": true,"htmlWhitespaceSensitivity": "ignore","endOfLine": "auto","trailingComma": "all","tabWidth": 2}

3、添加.prettierignore文件

/dist/*
/html/*
.local
/node_modules/**
**/*.svg
**/*.sh
/public/*

当代码不规范时执行如下就会提示错误:

 三、配置stylelintrc.cjs

1、安装依赖

pnpm add sass sass-loader stylelint postcss postcss-scss postcss-html stylelint-config-prettier stylelint-cnfig-recess-order stylelint-config-recommended-scss stylelint-config-standard stylelint-config-standard-vue stylelint-scss stylelint-order stylelint-config-standard-scss -D

2、配置.stylelintignore文件

/node_modules/*
/dist/*
/html/*
/public/*

3、配置.stylelintrc.cjs文件

// @see https://stylelint.bootcss.com/module.exports = {extends: ['stylelint-config-standard', // 配置stylelint拓展插件'stylelint-config-html/vue', // 配置 vue 中 template 样式格式化'stylelint-config-standard-scss', // 配置stylelint scss插件'stylelint-config-recommended-vue/scss', // 配置 vue 中 scss 样式格式化'stylelint-config-recess-order', // 配置stylelint css属性书写顺序插件,'stylelint-config-prettier', // 配置stylelint和prettier兼容],overrides: [{files: ['**/*.(scss|css|vue|html)'],customSyntax: 'postcss-scss',},{files: ['**/*.(html|vue)'],customSyntax: 'postcss-html',},],ignoreFiles: ['**/*.js','**/*.jsx','**/*.tsx','**/*.ts','**/*.json','**/*.md','**/*.yaml',],/*** null  => 关闭该规则* always => 必须*/rules: {'value-keyword-case': null, // 在 css 中使用 v-bind,不报错'no-descending-specificity': null, // 禁止在具有较高优先级的选择器后出现被其覆盖的较低优先级的选择器'function-url-quotes': 'always', // 要求或禁止 URL 的引号 "always(必须加上引号)"|"never(没有引号)"'no-empty-source': null, // 关闭禁止空源码'selector-class-pattern': null, // 关闭强制选择器类名的格式'property-no-unknown': null, // 禁止未知的属性(true 为不允许)'block-opening-brace-space-before': 'always', //大括号之前必须有一个空格或不能有空白符'value-no-vendor-prefix': null, // 关闭 属性值前缀 --webkit-box'property-no-vendor-prefix': null, // 关闭 属性前缀 -webkit-mask'selector-pseudo-class-no-unknown': [// 不允许未知的选择器true,{ignorePseudoClasses: ['global', 'v-deep', 'deep'], // 忽略属性,修改element默认样式的时候能使用到},],},
}

http://www.lryc.cn/news/311428.html

相关文章:

  • idea:springboot项目搭建
  • 如何保证某个程序系统内只运行一个,保证原子性
  • golang常见面试题
  • 探索Python编程世界:从入门到精通
  • Spark Shuffle Tracking 原理分析
  • Docker 干货系列 (持续更新)
  • 一.jwt token 前后端的逻辑
  • day12_oop_抽象和接口
  • linux 将 api_key设置环境变量里
  • java八股文复习-----2024/03/03
  • UE4 Niagara 关卡3.4官方案例解析
  • C# Onnx segment-anything 分割万物 一键抠图
  • Linux配置网卡功能
  • 【C++】十大排序算法之 归并排序 快速排序
  • x-pack的破解方式和免费jar包!!可直接用!!
  • 最新版本,Midjourney保姆级教程!
  • Android中的几种定位方式调用详解
  • 【软件测试】接口调不通排查分析+常遇面试题总结
  • c++基础学习第三天(指针,结构体)
  • 【数仓】zookeeper软件安装及集群配置
  • Qt 实现橡皮擦拭显示图片
  • Vue3+Element-Plus中ELMessage样式丢失处理
  • 97 spring 中的泛型类型注入
  • C++设计模式
  • 反向代购业务系统|无货源代购中国商品|反向海淘代购系统
  • Linux 进程间通信
  • hippy 调试demo运行联调-mac环境准备篇
  • 【golang】go module依赖的git tag被覆盖 如何处理 | 因测试产生大量的git tag 如何清除 最佳实践
  • Spring Cloud原理详解
  • 力扣76. 最小覆盖子串(滑动窗口)