This is a "Monorepo" Lerna setup with one React component and an additional library in another package that depends on it.
The build scripts will build and publish to npm with CJS, ES6 and UMD builds.
Jest and Cypress are included for tests. AirBnB lint rules (relaxed a bit) included, with Prettier exclusions. Demo site uses Parcel bundler.
git clone https://github.com/downplay/lerna-react-library-template
cd lerna-react-library-template
yarn
yarn global add lerna
lerna bootstrap
yarn build
To run demo:
yarn global add parcel
yarn start
To run Jest tests:
yarn test
To run e2e tests (uses cypress.io):
yarn e2e
- Change version in package.json
- Rename all lerna-react-library-template -> your-component-packages
- Rename all my-demo-component -> your-component
- Rename all my-demo-component-lib -> your-component-foo
- Rename packages/my-demo-component*
- Rename all MyDemoComponent and MyDemoComponentLib. Note: the new name will be used as the global name for UMB (browser) builds
- In package.json for each component, the
files
array must specify all your .js files, which will get built into the root of the package (but .gitignore will ignore them). Alsoes
andumd
are the folders with the ES6 and UMD builds respectively - If you want to add more libs, duplicate folders as needed and add to
lerna.json
To publish to npm
lerna publish
Bits and pieces borrowed from React Router (C) React Training MIT License https://github.com/ReactTraining/react-router
- First version
©2018 Downplay Ltd
Distributed under MIT license. See LICENSE for full details.