mkdir ‘组件名称’
npm init
将会生成package.json文件react
新建src目录做为组件的源代码目录,index.js做为组件入口
新建lib目录做为组件的编译后目录,这个目录只读npm
修改package.json的main字段为"src/index.js"或"lib/index.js"json
src/index.js中就能够编写组件了,导出组件app
export default class extends React.Component{ render(){ return ( <div>Hello,World!</div> ) } }
执行 npm link
在根目录下,create-react-app example
cd example && npm link '组件名称'
经过npm link命令,能够在本地模拟项目 npm install '组件名称'调试
接下来,你就能够在example项目中,code
import 组件名称 from “组件名称”
注册npm帐号
登录npm帐号
npm publish