Yarn workspaces utils for CRACO
npm install @tsed/yarn-workspacesAn util inspired
by react-workspaces
. This package, allow you to configure a CRACO project and
use yarn workspaces to create shared modules in the same mono
repository.
- A project configured with Yarn workspaces,
- CRACO
Install the @tsed/yarn-workspaces on the react project level generated with CRACO:
``bash`
yarn add -D @tsed/yarn-workspaces
Then edit or add the craco.config.js:
`js
const { configure, ensureReact } = require("@tsed/yarn-workspaces")
module.exports = {
webpack: {
configure: (webpackConfig, ctx) => {
webpackConfig = ensureReact(configure(webpackConfig, ctx))
// other things ...
return webpackConfig
}
}
}
`ensureReact
> function ensure that webpack only one version of react.
Now you can create a shared package in your packages directory. For example create a shared directory and add a
new package.json:
`json`
{
"name": "@project/shared",
"version": "1.0.0",
"main": "src/index.js"
}
Then, in the application package.json add the @project/shared as dependencies:
`json``
{
"name": "@project/app",
"version": "1.0.0",
"main": "src/index.js",
"dependencies": {
"@project/shared": "1.0.0"
}
}
Finally, imported a shared component in your App and start the application!