json_serializable.dart icon indicating copy to clipboard operation
json_serializable.dart copied to clipboard

Question about how to automate generation of .g.dart files.

Open Tamerlanchiques opened this issue 2 years ago • 2 comments

Hi. I would ask how to make integration of json_serializable more convenient in terms of repository that contains ready to run code base. I think that storing of generated files in repo is not optimal way and better to generate all necessary files on local machine. But new-comers in my project will be confused about how to generate missing files.

So my question is: Is that possible to automate process of generating missing .g.dart files? Maybe extension for VS Code or something?

My current thoughts is that I can make .sh script and run dart run build_runner build but it takes around 20 secs of time each run even if no files missing.

Tamerlanchiques avatar Aug 10 '23 14:08 Tamerlanchiques

How about a Makefile with the following contents:

watch:
        dart run build_runner watch -d

And then in your readme ask users to run make watch in their terminal. This will automatically re-generate code as needed.

emesterhazy avatar Sep 14 '23 05:09 emesterhazy

You can just run this command, it will watch and regenerate the code if needed only.

dart run build_runner watch --delete-conflicting-outputs

3kdeveloper avatar Feb 11 '24 15:02 3kdeveloper