3

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?

Fran
  • 59
  • 1
  • 7
  • Isn't this something `build_runner` already does? If everything is up-to-date, it takes only a few seconds for me to figure out 0 things need to be changed. This may depend on the things that are generated, though. For me, that's a [drift](https://pub.dev/packages/drift) database – fravolt Jul 06 '22 at 07:24

2 Answers2

3

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
Kaushik Chandru
  • 15,510
  • 2
  • 12
  • 30
2

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/

Gpack
  • 1,878
  • 3
  • 18
  • 45