This is just a quick monorepo test with yarn workspaces and create react app.
Workspaces are a new way to setup your package architecture that’s available by default starting from Yarn 1.0. It allows you to setup multiple packages in such a way that you only need to run yarn install once to install all of them in a single pass.
Workspaces are stable enough to be used in large-scale applications and shouldn’t change anything to the way the regular installs work
npm install -g create-react-appnpm install -g yarn
create-react-app project_name
yarn eject
- Create a .yarnrc file with the line
workspaces-experimental true
You just need to add the following line in your root package.json.
"workspaces": [ "packages/*" ]
- Create your
/packagesin the root directory or anywhere you want them to be.
- In your packages directory, create an directory of your choise app, main, entry are common choices.
cd packages/appnpm initto create a package.jsonyarn add reactandyarn add react-domto install dependencies of the main app
-Next you need to edit the webpack configuration to look into the right locations.
-All path configurations are found in the config/paths.js file.
-You will only need to edit the appIndexJs and appSrc variables.
module.exports = {
...
appIndexJs: resolveApp('packages/app/index.js'),
...
appSrc: resolveApp('packages'),
...
};
Finally, run yarn install somewhere, ideally inside the workspace root. All your project dependencies will be installed together, giving Yarn more latitude to better optimize them.
If everything works well, you should now have a similar file hierarchy:
- config
- node_modules
- packages
- app
- App.css
- App.js
- App.test.js
- index.css
- index.js
- logo.svg
- package.json
- registerServiceWorker.js
- package-alpha
- index.js
- package.json
- package-beta
- index.js
- package.json
- public
- scripts
- .gitignore
- package.json
yarn startComes from create-react-app and will start a webpackDevServer at http://localhost:3000/ with hot reloading and the whole shebang
yarn buildCreates a production build in the/builddirectory