Melos requires a few one-off steps to be completed before you can start using it.
Melos can be installed as a global package via pub.dev:
dart pub global activate melos
To set up your project to use Melos, create a
melos.yaml file in the root of the project.
melos.yaml file, add
name: my_project packages: - packages/**
packages list should contain paths to the individual packages within your project. Each path
can be defined using the glob pattern expansion format.
true, if you are using Dart 2.17.0 or greater:
command: bootstrap: usePubspecOverrides: true
This enables a new mechanism for linking local packages, which integrates better with other tooling
flutter tool, IDE plugins) than the mechanism currently being used
by default. Please read the documentation for
before enabling this feature.
Once installed & setup, Melos needs to be bootstrapped. Bootstrapping has 2 primary roles:
- Installing all package dependencies (internally using
- Locally linking any packages together.
In normal projects, packages can be linked by providing a
path within the
pubspec.yaml. This works for small
projects however presents a problem at scale. Packages cannot be published with a locally defined path, meaning
once you're ready to publish your packages you'll need to manually update all the packages
with the versions. If your packages are also tightly coupled (dependencies of each other), you'll also have to manually
check which versions should be updated. Even with a few packages this can become a long and error-prone task.
Melos solves this problem by overriding local files which the Dart analyzer uses to read packages from. If a local package
exists (defined in the
melos.yaml file) and a different local package has it listed as a dependency, it will be linked
regardless of whether a version has been specified.
Once successfully bootstrapped, you can develop your packages side-by-side with changes to a single package immediately reflecting across other dependent packages.
Melos also provides other helpful features such as running scripts across all packages. For example, to run dart analyzer in each package, add a new
script item in your
name: my_project packages: - packages/** scripts: analyze: exec: dart analyze .
Then execute the command by running
melos run analyze.
If you're looking for some inspiration as to what scripts can help with, check out the FlutterFire repository.
If you are using VS Code, there is an extension available, to integrate Melos with VS Code.