iDecode
iDecode

Reputation: 28906

fromJson and toJson not generated when the build code is put in build.yaml file

If I use the following code in pubspec.yaml file, then the build_runner generates code but if I put it in the build.yaml file, then the code is not generated for fromJson and toJson.

targets:
  $default:
    builders:
      json_serializable:
        enabled: true
        generate_for:
          include:
            - lib/foo.dart

I also want to know, whether I include (or not include) any files above, the code takes same amount of time to generate. So, how can I then generate the code for a specific file/directory, like first generate for foo.dart and later on I want to generate code for bar.dart keeping foo.dart and foo.g.dart intact.

Upvotes: 0

Views: 505

Answers (1)

fartem
fartem

Reputation: 2531

If you are placing this code in build.yaml then yes, build_runner use it as configuration and will generate a files that you include in your config. If you are placing this code in pubspec.yaml file build_runner will not use it because pubspec.yaml doesn't config file for build_runner.

When you are working with build_runner you can listend and rebuild any changes automatically with watch argument:

flutter pub run build_runner watch --delete-conflicting-outputs

Upvotes: 0

Related Questions