Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce Flutter's build_runner build time

My project is getting really big and every time I run build_runner it takes too much time to build. My idea to reduce the build time is to build only files that actually need building and those are files of my current feature directory.

Is there a way to run build_runner only for a single folder or a single file?

like image 751
Fran Avatar asked Oct 16 '25 19:10

Fran


2 Answers

You can set enabled true or false in builder .

targets:
  $default:
    builders:
      your_builder:
        generate_for:
          - lib/**/*.dart
      mockito:mockBuilder:
        enabled: false
      json_serializable:
        enabled: true
like image 142
Kaushik Chandru Avatar answered Oct 19 '25 08:10

Kaushik Chandru


I found that using generate_for for individual builders is a good way to increase the speed.
You could:

  1. Move the related files in a dedicated folder and then
$default:
  builders:
    your_builder:
      generate_for:
        - lib/path/to/folder/**.dart
  1. Add a special extension to your files. For example, for json_serializable, I suffix my files with .json.dart and then I use lib/**.json.dart for the generate_for.

More info here: https://codewithandrea.com/tips/speed-up-code-generation-build-runner-dart-flutter/

like image 24
Gpack Avatar answered Oct 19 '25 08:10

Gpack