Basic recipe to start monorepo project for flutter
- 
Install melos (more details about melos: https://melos.invertase.dev/) 
 dart pub global activate melos
- 
Create a project folder 
 mkdir flutter_project cd flutter_project
- 
Add melos.yamlfile
 name: flutter_skeleton packages: - packages/** - apps/** command: bootstrap: usePubspecOverrides: true scripts: analyze: exec: flutter analyze . outdated: exec: flutter pub outdated test: exec: flutter test
- Create - .gitignoreand add- pubspec_overrides.yamlin it.
- 
Create the main app 
 mkdir apps # create dir for applications cd apps flutter create main_app
- 
Add a library package 
 cd .. # go back to the root dir of the project mkdir packages # create dir for shared packages cd packages flutter create --template=package lib_example
- 
Bootstrap melos 
 melos bs # melos bootstrap
- 
Try melos scripts added in melos.yamlfile
 melos analyze # run analyze for all packages melos test # run test for all packages melos outdated # check outdated pub dependencies for all packages melos upgrade # Update dependencies for all packages
That's it! Now you have the monorepo project ready to start. You can open the root directory with vscode or IntelliJ(Or Android Studio). melos already bootstrapped the IntelliJ project. Nothing to do with vscode, but you can install the extension if it makes your life easier.
More information: https://melos.invertase.dev/ide-support
Use the shared package from the main app
Add the package name as a dependency in the pubspec.yaml
Something like:
dependencies:
  lib_example:
    path:../packages/lib_example
You can indicate the package version instead of the path if you ever published the package to the pub.dev. I had to put path because flutter pub outdated doesn't respect the pubspec_overrides.yaml for the local dependency for the moment.
The complete code can be found on github
 

 
    
Top comments (0)