--- title: 开发指南 --- ### 环境 * node = 8+ * npm = 3+ ### 开发流程 #### 创建组件 ```shell $ npm install # 安装依赖 $ npm run create # 新增组件, 根据提示填写组件信息 ``` > 需安装[vue-cli](https://cli.vuejs.org/), v3.0+还需安装[@vue/cli-init](https://www.npmjs.com/package/@vue/cli-init) #### 开发组件 ```shell $ npm run dev # 访问 http://localhost:4000/[组件名称] $ npm run dev -- --component [COMPONENT NAME] # npm run dev -- --component button, 访问 http://localhost:4000 ``` #### 测试组件 ```shell $ npm test # 全部测试 $ npm run test [component name] # 测试单个组件 ``` #### feature/bugfix 新的大版本开发会在统一的开发分支中进行,其他单个组件增加新功能或问题修复流程如下: ```shell $ git checkout -b [feature_xxx/fix_xxx] origin/dev # 开发 $ git add --all $ git commit -am "描述" # 描述参考【Commit规范】git cz $ git pull --rebase origin dev # 解决冲突 $ git push origin [feature_xxx/fix_xxx] # 提交 PR 至 dev 分支, 指定相应人员 review, 根据反馈进一步修改提交 $ git checkout dev $ git pull ``` ### 代码规范 #### 目录规范 ``` ├── build 构建脚本 ├── config 构建环境配置 ├── test 测试配置 ├── components 组件代码 ├── _style 通用样式,图标 ├── _util 通用工具方法 ├── button 组件目录 ├── demo 组件示例 ├── test 组件单元测试用例 ├── index.vue 组件核心代码 ├── ... 组件其他辅助代码或子组件代码 ├── README.md 组件说明文档 ├── ... ├── examples 组件库示例 ├── site 组件库文档站点 ├── ... ``` #### 组件规范 ##### 组件命名 * 组件名(kebab-case)使用小写字母,以 `-` 分割, 例如 `image-reader`。 * 准确表达组件UI或功能且避免过于宽泛。 ##### 组件实现 * 依赖 新增外部依赖需要与核心开发成员讨论后决定,尽量选择较为知名开源组件,且避免体积过大。 * 引用 组件内部使用相对路径引用,避免使用`alias`。如`import { extand } from '../util'`。 * 通用方法 通用逻辑和样式使用`_style/*`, `_util/*`, 避免组件代码内部通用逻辑或样式冗余【新增需讨论】 * 样式 使用`stylus`; 单位统一使用`px`; 所有图标使用内置svg图标, 详情见组件`Icon`。 注意:通用样式,工具方法的详细使用文档参考Wiki,[Style](https://github.com/didi/mand-mobile/wiki/Style),[Utils](https://github.com/didi/mand-mobile/wiki/Utils),[Scroll](https://github.com/didi/mand-mobile/wiki/Scroll),[FormatValue](https://github.com/didi/mand-mobile/wiki/FormatValue) ##### 组件核心代码 原则上以官方[vue-sytle-guide](https://vuejs.org/v2/style-guide/#Component-instance-options-order-recommended)为标准,常用部分如下: ```html