Monorepo supports local packages.
When using local packages in a monorepo, you might experience peer dependency problems because you use symbolic links.
But if you use lopm
, hard links the files declared in the files
field in the package.json
In other words, it has the same effect as a package installed by the npm registry.
It is similar to dependenciesMeta.*.injected of pnpm, but sync is difficult periodically at current pnpm and does not support watch mode.
- pnpm
$ pnpm install lopm -D -w
$ pnpm lopm -v
- yarn
$ yarn add lopm -D
$ yarn lopm -v
- npm
$ npm install lopm --save-dev
$ npm lopm -v
-
lopm list
Displays a list of available local packages and local packages specified in the current project.
- Example
{ "name": "foo", "dependencies": { "bar": "workspace:^1.0.0", "bar2": "workspace:^1.0.0" } }
-
lopm sync
Hardlink the local packages.
Example:
node_modules
capacity increases due to changes from pnpm symbolic links to hard links. -
lopm run <command>
The command entered in the parameter is executed.
While command is running,lopm
runs in watch mode.
Monitor thefiles
field in the local packagepackage.json
and when a change occurs, thesync
command is executed after 3 seconds.
Specify files
field to export out
- example
"name": "bar"
...
"files": [
"dist",
"package.json"
],
...
After pnpm install
or yarn install
, synchronization must be performed through the lopm sync
command.
That is, it must be done immediately before build or development.
The lopm run <command>
command is in watch mode. Hard link again if any changes to the local package occur while the command is running.
The command pnpm install
or yarn install
will restore it.
- example
"name": "foo"
...
"scripts": {
"build": "lopm sync && vite build",
"dev": "lopm run vite"
},
...
The dependency
field must specify the local package name.
Supports workspace
, link
and file
protocols.
- example
"name": "foo"
...
"dependencies": {
"foo": "workspace:0.0.1",
"foo2": "link:../../packages/foo",
"foo3": "file:../../packages/foo",
},
...
If you followed the example above well, you can use it inside the bar
package as follows:
$ pnpm lopm sync
// This code in "bar" package
import { sum } from "foo";
Similar to the original Getting Started, except that there is a scripts
field in package.json and a turbo.json
file.
"name": "bar"
...
"scripts": {
"sync": "lopm sync",
"build": "vite build",
},
...
"name": "monorepo-root"
...
"scripts": {
"build": "turbo rub build --filter='./packages/bar'",
},
...
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"dependsOn": ["sync"]
},
}
}
Even if you set this much, Turbo will sync before the build!