⚛️ Zero Config Create-React-App Monorepos with Yarn Workspaces, Lerna and React Storybook.
⚛️ Zero Config Create-React-App Monorepos with Yarn Workspaces, Lerna and React Storybook.
Now supports TypeScript and React-App-Rewired!
git clone [email protected]:react-workspaces/react-workspaces-playground.git
cd react-workspaces-playground
yarnyarn workspace This will run the chosen Yarn command in the selected workspace.
Example:
yarn workspace my-app add react-router-dom --devThis will add react-router-dom as dependencies in your packages/my-app/package.json. To remove dependency use remove instead of add
From your project root type start command for desired app
yarn workspace @project/app-single-comp startAll available start scripts
"scripts": {
"start:app-ant-design": "yarn workspace @project/app-ant-design-rewired start",
"start:app-multi": "yarn workspace @project/app-multi-comps start",
"start:app-single": "yarn workspace @project/app-single-comp start",
"start:app-ts": "yarn workspace @project/app-typescript start",
"start:storybook": "yarn workspace @project/storybook storybook",
"start:storybook-ts": "yarn workspace @project/storybook-typescript storybook",
...
}yarn start:storybookyarn workspace testUpdate the homepage URL in app-one/package.json to reflect your GitHub Pages URL.
{
"name": "@project/app-single-comp",
"private": true,
"homepage": "https://react-workspaces.github.io/react-workspaces-playground",
"scripts": {
"deploy": "gh-pages -d build"
}
}Run the deploy script.
yarn workspace deployUse Create React App's --scripts-version flag to create a new React App with Yarn Workspaces support.
create-react-app --scripts-version @react-workspaces/react-scripts my-appTo create new TS app use Create React App's --template flag with --scripts-version flag to create a new React App with Yarn Workspaces support and Typescript.
npx create-react-app --scripts-version @react-workspaces/react-scripts --template typescript my-ts-appReact Workspaces Playground uses a custom version of react-scripts under the hood. The custom react-scripts is an NPM package to use in place of the react-scripts dependency that usually ships with Create React App. See: (@react-workspaces/react-scripts) on NPM.
Support for Yarn Workspaces was added by:
Adding yarn-workspaces.js file to resolve workspaces modules.
Updating the Webpack config:
Use main:src in package.json for loading development source code.
Use production or development settings based on your yarn workspaces settings in your /package.json:
{
"workspaces": {
"packages": ["packages/apps/*", "packages/components", "packages/storybook"],
"production": true,
"development": true,
"package-entry": "main:src"
}
}Minimal updates to the Webpack config were required.
Diff: webpack.config.js
…No open issues yet, or sync has not completed.