通用React组件开发过程

作者:日期:2017-11-24 14:27:49 点击:107

 

1. 在你的github建立组件 git 库

  • git@github.com:GuoYongfeng/rc-component-tutorial.git

2. 搭建脚手架

npm install rc-tools yo generator-rc -g
mkdir rc-component
cd rc-component
yo rc --port=8000 --author=guoyongfeng --rc_version=1.0.0

2.1 目录结构

- .travis.yml
- examples
 - index.js
 - index.html
- lib
 - Component.js
- index.js
- tests
  - index.spec.js
- package.json

3. 源码

  • 在 lib 目录中写 js,在 assets 目录下写 less,在 tests 目录下写 测试用例,代码规范参考 react 组件代码规范.
  • examples 中的 html 不可修改,通过 js 中的 jsx 渲染页面,通过 require css 引入 css
  • 开发中用到其他公共库,通过 npm install --save 以及 npm install --save-dev 来安装
  • 组件设计可参考 react 组件设计原则.

4. 启用开源平台服务

4.1 travis-ci

使用 github 账号登陆 travis 后访问 http://https://travis-ci.org/profile 开启对应 git 库

4.2 coveralls.io

使用 github 账号登陆 coveralls 后访问 https://coveralls.io/repos/new 开启对应 git 库

4.3 saucelabs.com

5. 开发调试

  • 在项目根目录执行 npm install
  • 在项目根目录执行 npm start
  • 打开 http://localhost:xxxx 访问库, xxxx 为脚手架配置的网络端口
  • 打开 http://localhost:xxxx/examples/index.html 查看示例
  • 打开 http://localhost:xxxx/tests/runner.html 运行测试

6. 支持 spm

  • npm install spm -g
  • 修改 package.json 将源码中用到的库,从 dependencies 字段复制到 spm 字段
{
  "devDependencies":{
    "react": "0.14.x"
  },
  "spm":{
    "dependencies":{
      "react": "0.14.x"
    }
  }
}

7. 浏览器支持版本

  • ie8, ie8+, chrome, firefox 最新版
  • 可适当渐进降级,如 css 动画可以不支持 ie8

8. 功能要求

  • 支持基本的键盘访问,最好支持 WAI-ARIA

9. 支持 HISTORY.md

  • 通过在根目录运行 npm run history 生成 HISTORY.md
  • 需要建立必要的 milestone,issue,label,参见: https://github.com/yiminghe/gh-history
  • milestone 标题为语义化版本号,issue 属于某个 milestone,并且具备 label
  • label 为枚举,包括
    • new 新增的属性、功能、方法、特性等等
    • fixed 修复 bug 和影响使用的性能问题等
    • improved 接口增强、健壮性和性能提升、代码优化、依赖模块升级等。
    • changed 涉及到兼容性变化的改动。

10. 发布

  • 在根目录运行 npm publish

上一篇: React/JSX 编码规范

下一篇: React技术分享