chenfei-hnu / Blog

个人整理的跟前端相关的文档 ( This is some front-end development related documentation )
9 stars 2 forks source link

前端团队编码中的各项规范 #54

Open chenfei-hnu opened 3 years ago

chenfei-hnu commented 3 years ago

编码规范

前端编码规范在此项目实践中需注意的规范点

目录和文件命名

  1. 目录和文件名不能以数字开头,语义化命名
  2. 非特殊情况,目录和文件名默认采用 kebab-case 方式,即以全小写字母加 - 连接(新项目强制执行,旧项目根据情况尽量遵守)
  3. 内容有复数结构时,采用复数形式命名,如 utils、styles

文件夹分类

api 所有后台接口声明 assets 所有图片、文件等静态资源 styles 公共样式 components 公共组件、公共容器 router 路由 icon 所有icon图标 config 常量,固定配置 lang 国际化 utils 公共工具类或函数 pages 页面,对应路由 redux 公共仓库 types TS类型声明

代码格式

  1. 缩进使用2个空格或软tab设置为2个空格
  2. 代码片段、变量和符号间留适当空格

语义化标签

模块容器

整体模块(页面,弹窗) main { padding: 24px; box-shadow: 0 1px 4px 0 rgba(0,0,0,.1); border-radius: 2px; background: #fff; }
顶部模块 header { display: flex; align-items: center; margin-bottom: 24px; }
内容主体