Monorepo
Yarn workspace
- Add packages folder configs to
package.json
.
{
"private": true,
"workspaces": {
"packages": [
"packages/*"
],
"nohoist": []
},
}
- Create package folder
mkdir packages/core
- Config
pacakge.json
of workspace
{
"name": "@my-workspace/core",
"version": "1.0.0"
}
- Add sample function to ensure it works
index.js
function foo() {
console.log("hello workspace");
}
export default foo;
index.d.ts
declare function foo(): void;
export default foo
- Install worksapce pacakge in main project
yarn -W add @my-workspace/core@1.0.0
{
"dependencies": {
+ "@my-workspace/core": "1.0.0"
}
}
- Import package in apps.
import foo from "@my-workspace/core"
foo()