I am using EasyLocalization
, mobx
, JsonSerializable
etc. To generate *.g.dart
files, I am using build_runner watch
or the script in scripts/build.sh
:
flutter packages pub run build_runner build
It was taking 2 seconds at most, but then suddenly it started to take at least 10 seconds or sometimes 30 seconds . Because of this situation, build_runner watch
became useless, I mean it's not working properly since then.
The output on the console when I run my script:
$ sh scripts/build.sh
[INFO] Generating build script...
[INFO] Generating build script completed, took 611ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 126ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 745ms
[INFO] Running build...
[INFO] 1.2s elapsed, 0/16 actions completed.
[INFO] 2.2s elapsed, 0/16 actions completed.
[INFO] 3.3s elapsed, 0/16 actions completed.
[INFO] 12.5s elapsed, 1/17 actions completed.
[INFO] 13.6s elapsed, 4/20 actions completed.
[INFO] Running build completed, took 14.6s
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 57ms
[INFO] Succeeded after 14.6s with 2 outputs (47 actions)
I finally decided to try and solve this myself, I've improved it slightly by adding the following to my pubspec.yaml: Eg
targets:
$default:
builders:
json_serializable:
enabled: true
generate_for:
include:
- lib/your_codegen_folder/**.dart
- lib/**.gen.dart
Hope this speeds it up a little for you. You'll have to add builder configs for your other two generators like the json_serializable one here. I suspect they might be referred to easy_localization
and mobx
? I don't know, I'm new to this.
In addition to avoiding running builders on unnecessary inputs I manage to make my builds MUCH faster by disabling the mockito mock generator, which I was not using:
targets:
$default:
builders:
your_builder:
generate_for:
- lib/**/*.dart
mockito:mockBuilder:
enabled: false
Running a build was causing Mockito to search every one of my test files for @GenerateMocks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.