1
0
Fork 0
freesewing/packages/create-freesewing-pattern/readme.md

143 lines
6.3 KiB
Markdown
Raw Normal View History

# create-react-library
2018-03-04 15:43:18 -05:00
> CLI for easily publishing modern React libraries with Rollup and example usage via create-react-app.
2018-03-04 15:43:18 -05:00
2018-08-02 16:14:43 -04:00
[![NPM](https://img.shields.io/npm/v/create-react-library.svg)](https://www.npmjs.com/package/create-react-library) [![Build Status](https://travis-ci.com/transitive-bullshit/create-react-library.svg?branch=master)](https://travis-ci.com/transitive-bullshit/create-react-library) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
2018-03-04 15:43:18 -05:00
2018-03-04 15:43:18 -05:00
## Intro
**The purpose of this CLI is to make publishing your own React components as simple as possible.**
<p align="center">
2018-03-07 03:13:07 -05:00
<img width="600" src="https://cdn.rawgit.com/transitive-bullshit/create-react-library/master/media/demo.svg">
</p>
2018-03-04 21:01:30 -05:00
2018-03-04 15:43:18 -05:00
## Features
2018-03-12 19:58:04 -04:00
- Easy-to-use CLI
- Handles all modern JS features
2018-04-21 18:32:31 -04:00
- Bundles `cjs` and `es` module formats
2018-03-12 19:58:04 -04:00
- [create-react-app](https://github.com/facebookincubator/create-react-app) for example usage and local dev
- [Rollup](https://rollupjs.org/) for build process
- [Babel](https://babeljs.io/) for transpilation
2018-03-12 19:58:59 -04:00
- [Jest](https://facebook.github.io/jest/) for testing
2018-03-12 19:58:04 -04:00
- Supports complicated peer-dependencies
- Supports CSS modules
- Optional support for TypeScript
2018-03-12 19:58:04 -04:00
- Sourcemap creation
2018-07-09 08:09:29 -04:00
- Hundreds of public modules created
2018-03-12 19:58:04 -04:00
- Thorough documentation :heart_eyes:
2018-07-09 08:08:01 -04:00
- [Chinese docs](./readme.zh-CN.md) by [@monsterooo](https://github.com/monsterooo)
2018-03-04 15:43:18 -05:00
2018-03-04 15:43:18 -05:00
## Install
This package requires `node >= 4`, but we recommend `node >= 8`.
2018-03-04 15:43:18 -05:00
```bash
npm install -g create-react-library
2018-03-04 15:43:18 -05:00
```
2018-03-04 15:43:18 -05:00
## Creating a New Module
```bash
create-react-library
2018-03-04 15:43:18 -05:00
```
2018-03-04 15:51:45 -05:00
Answer some basic prompts about your module, and then the CLI will perform the following steps:
2018-03-04 15:43:18 -05:00
- copy over the template to a new folder in the current directory
2018-03-04 15:49:34 -05:00
- install dependencies via yarn or npm
2018-03-04 15:51:45 -05:00
- link packages together for local development
2018-03-04 15:43:18 -05:00
- initialize local git repo
2018-03-04 21:03:33 -05:00
At this point, your new module should resemble this screenshot and is all setup for local development.
2018-03-04 15:43:18 -05:00
<p align="center">
2018-03-07 03:13:07 -05:00
<img width="600" src="https://cdn.rawgit.com/transitive-bullshit/create-react-library/master/media/tree.svg">
</p>
2018-03-04 20:59:35 -05:00
2018-03-04 21:03:33 -05:00
## Development
2018-03-04 20:59:35 -05:00
2018-03-04 15:43:18 -05:00
Local development is broken into two parts.
2018-03-04 15:49:34 -05:00
First, you'll run rollup to watch your `src/` module and automatically recompile it into `dist/` whenever you make changes.
2018-03-04 15:43:18 -05:00
```bash
2018-03-04 15:49:34 -05:00
npm start # runs rollup with watch flag
2018-03-04 15:43:18 -05:00
```
2018-03-04 15:49:34 -05:00
The second part will be running the `example/` create-react-app that's linked to the local version of your module.
2018-03-04 15:43:18 -05:00
```bash
# (in another tab)
cd example
npm start # runs create-react-app dev server
```
2018-07-06 15:33:31 -04:00
Now, anytime you make a change to your library in `src/` or to the example app's `example/src`, `create-react-app` will live-reload your local dev server so you can iterate on your component in real-time.
2018-03-04 15:43:18 -05:00
![](https://media.giphy.com/media/12NUbkX6p4xOO4/giphy.gif)
2018-03-04 15:49:34 -05:00
2018-07-06 15:33:31 -04:00
#### Publishing to NPM
2018-08-05 19:02:53 -04:00
The only difference when publishing your library to **npm** is to make sure that any npm modules you want as peer dependencies are properly marked as `peerDependencies` in `package.json`. The rollup config will automatically recognize them as peers and not try to bundle them in your module.
2018-03-04 15:43:18 -05:00
Then publish as per usual.
```bash
# note this will build `commonjs` and `es`versions of your module to dist/
npm publish
```
2018-03-04 15:43:18 -05:00
#### Github Pages
Deploying the example to github pages is simple. We create a production build of our example `create-react-app` that showcases your library and then run `gh-pages` to deploy the resulting bundle. This can be done as follows:
```bash
npm run deploy
```
2018-03-04 15:43:18 -05:00
## Examples
### Multiple Named Exports
Here is a [branch](https://github.com/transitive-bullshit/react-modern-library-boilerplate/tree/feature/multiple-exports) which demonstrates how to use multiple named exports. The module in this branch exports two components, `Foo` and `Bar`, and shows how to use them from the example app.
### Material-UI
Here is a [branch](https://github.com/transitive-bullshit/react-modern-library-boilerplate/tree/feature/material-ui) which demonstrates how to make use of a relatively complicated peer dependency, [material-ui](https://github.com/mui-org/material-ui). It shows the power of [rollup-plugin-peer-deps-external](https://www.npmjs.com/package/rollup-plugin-peer-deps-external) which makes it a breeze to create reusable modules that include complicated material-ui subcomponents without having them bundled as a part of your module.
### Boilerplate
The CLI is based on this [boilerplate](https://github.com/transitive-bullshit/react-modern-library-boilerplate), which you can optionally read about [here](https://hackernoon.com/publishing-baller-react-modules-2b039d84bce7).
2018-05-06 19:07:52 -04:00
### Libraries
Here are some example libraries that have been bootstrapped with `create-react-library`.
- [tabler-react](https://github.com/tabler/tabler-react) - React components and demo for the Tabler UI theme.
- [react-background-slideshow](https://github.com/transitive-bullshit/react-background-slideshow) - Sexy tiled background slideshow for React 🔥
2018-05-07 18:30:58 -04:00
- [react-starfield-animation](https://github.com/transitive-bullshit/react-starfield-animation) -Canvas-based starfield animation for React ✨
2018-05-06 19:07:52 -04:00
- [react-particle-effect-button](https://github.com/transitive-bullshit/react-particle-effect-button) - Bursting particle effect buttons for React 🎉
2018-05-07 18:32:11 -04:00
- [react-particle-animation](https://github.com/transitive-bullshit/react-particle-animation) - Canvas-based particle animation for React 🌐
2018-05-07 18:33:22 -04:00
- [react-block-image](https://github.com/transitive-bullshit/react-block-image) - React replacement for img with more control + fallback support 🌃
2018-05-06 19:07:52 -04:00
- [react-mp3-recorder](https://github.com/transitive-bullshit/react-mp3-recorder) - Microphone recorder for React that captures mp3 audio 🎵
2018-05-31 09:08:26 -04:00
- [react-before-after-slider](https://github.com/transitive-bullshit/react-before-after-slider) - A sexy image comparison slider for React.
2018-05-25 19:50:35 -04:00
- [worldwind-react-globe](https://github.com/emxsys/worldwind-react-globe) - NASA WorldWind globe component for React.
2018-07-06 15:33:31 -04:00
- [react-shimmer](https://github.com/gokcan/react-shimmer) - Shimmer effect for loading images.
2018-07-28 07:33:13 -04:00
- [react-login-modal-sm](https://github.com/Silind/react-login-modal-sm) - Customizable React social media login modal.
2018-08-05 19:02:53 -04:00
- ... and hundreds more!
2018-05-06 19:07:52 -04:00
2018-08-05 19:03:05 -04:00
Want to add yours to the list? Submit an [issue](https://github.com/transitive-bullshit/create-react-library/issues/new).
2018-05-06 19:07:52 -04:00
2018-03-04 15:43:18 -05:00
## License
MIT © [Travis Fischer](https://github.com/transitive-bullshit)