build_runner
integrated right into VS Code. Run it on specific files / projects from context menu or command palette.
Features
Menu (Command Palette)
build_runner
can be ran on the whole workspace, specific project or on the active file through a build_runner menu. Open it by using a predefined keybinding ctrl+B
+ ctrl+R
(Windows / Mac / Linux):
If you want to run build_runner
on a specific file, e.g. user.g.dart
. Right click the file (or files) 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 run build_runner
on part files by selecting the main file (e.g., user.dart
). The extension will identify all associated part files, such as user.freezed.dart
and user.g.dart
, and execute the command on them.
- 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
Are monorepos supported?
Yes, the extension works in monorepos. The build_runner menu) lists all supported projects. When working with files, the extension automatically detects the associated project and runs code generation for that project.
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.