- 新建项目
mkdir component-name && cd $_
npx create-react-library
touch README.md
- 开发
# run example to start developing your new component against
npm link # the link commands are important for local development
npm install # disregard any warnings about missing peer dependencies
npm start # runs rollup with watch flag
# (in another tab, run the example create-react-app)
cd example
npm link react-poop-emoji
npm install
npm start # runs create-react-app hot-reload dev server
- 编写 Example
使用 create-react-app
// example/src
import React, { Component } from 'react'
import PropTypes from 'prop-types'
// example of built-in support for importing css styles (optional)
import './styles.css'
export default class ExampleComponent extends Component {
static propTypes = {
text: PropTypes.string
}
render() {
const {
text
} = this.props
return (
<div>
Example Component: {text}
</div>
)
}
}
- Git Stuffs
# be sure to update docs
vim README.md
vim package.json
# init and push git repo
git init
git add *
git commit -am "init"
# add git remote and push to remote github repo
- NPM Stuffs
# update dependencies, devDependencies, and peerDependencies
vim package.json
vim rollup.config.js
# build dist and publish to npm
npm publish
- Github Pages
npm run deploy