/react-component-template

https://github.com/JaKXz/react-component-template/wiki

Primary LanguageHTML

react-component-template

Quickly degit a modern [for now] React component that is publish-ready in one step with a gh-pages deployable example that has profiling enabled by default.

Inspired by svelte-component-template and create-react-library.

Getting started

Replace yarn commands with your package manager's equivalent.

0. Clone

Use GitHub's "Use this template" button or clone the project manually:

npx degit jakxz/react-component-template <project-name>

cd project-name

git init
yarn install
cd example
yarn install

1. Name your package

Do a find and replace for react-component-template and replace all instances with the name that you want :) this keeps the template lean, removing the need for any additional scripting. You are now able to publish your package to npm! 🎉 For "a better npm publish", try np.

2. rollup options can be found at https://github.com/developit/microbundle#readme

The defaults are set to work with the latest version of React (v17 at time of writing) and should suffice for most projects.

The React peer dependency [for consumers] is set by default to >=16.8, assuming the use of React hooks.

Workflow

yarn start

Then, open a new terminal tab in your project directory:

cd example
yarn
yarn start

You should be able to change files in src that are used in your example, e.g. ./src/index.tsx and see your example hot reload.

yarn test / setup

Tests are run via react-scripts from CRA. You can customize the config as documented.

Tip: run tests without watch mode with yarn test --watchAll=false.

Deploy ./example to gh-pages

In the root of your project, run:

yarn deploy

The example is just a standard (pre-ejected) CRA app whose dependencies are linked to the root folder (your React component). If you are adding more dependencies that will be shared with both the example & the React component, add them to the root package.json follow the link:../node_modules/<dep> pattern in ./example/package.json.

License

MIT © JaKXz