Bring build_runner
to your context menu. Shorten code generation times by building / watching specific files instead of the whole codebase in just two clicks.
Features
You can quickly run build_runner
on either the whole workspace or on the active file through a build_runner menu. Open it by using a predefined keybinding ctrl+B
+ ctrl+R
:
If you want to run build_runner
on a specific file, e.g. user.g.dart
, simply right click the file and select the command you need, Build This / Watch This.
- Build This: Regenerate the code for specified files directly targeting it with
build_runner
.
- Watch This: Continuously monitor and regenerate code for specified files, automatically applying changes as you work.
You can also run build_runner
on part files. No, there's don't need to multiselect all the files: the extension will do it for you. Just select the main file, such as user.dart
, and the extension will gather all the associated part files, like user.freezed.dart
and user.g.dart
, and will run the command on those files.
- Build Parts: Regenerate the code for
part
s of selected files.
- Watch Parts: Continuously monitor and regenerate code for
part
s of specified files, automatically applying changes as you work.
How does it work?
build_runner
has a parameter build-filter
that allows to specify which files to include for code generation.
dart build_runner build --build-filter=lib/user.g.dart
...and instead of regenerating the whole codebase, it will only regenerate lib/user.g.dart
. Although running this command with terminal is not always convenient (especially if you want to run it on multiple files). This VS Code extension puts this command to your context menu. So just right click the needed files, select the required command and you're covered.
Once ran, it collects required files (part directives for part commands and selected files for this commands) and exectues the build
/watch
command in a new terminal window.
Important: Generated files must be used, not source files. E.g. if you have a user.dart that is used to generate user.freezed.dart class, the freezed class must be used as a parameter.
FAQ
How do I delete-conflicting-outputs?
If you want to add / remove this flag, you can enable / disable it in the settings of this extension. Or you can open the command palette and run Enable / Disable delete conflicting outputs
command.
Can I run this on folders?
Yes, you can run this on both files and folders. Speaking of folders, only the part
type of commands is supported. It checks all the files within a folder (and subfolders), collects the part directives and runs a build_runner
.
Is multiselect supported?
Yes, you can run this command on multiple files / folders at once.
Can I run this in parallel?
Yes, the command is ran in a new terminal window each time it is executed. Meaning that you can run the watch
command on the File A
and then run the build
command on the File B
. For your convenience, you can rename terminal windows yourself to not mix them up.