Automatically run build_runner when opening a Dart or Flutter project
See original GitHub issueFor the time being, we have to run pub run build_runner watch
(or flutter packages pub run build_runner watch
for Flutter) each time we are working on a project with code generation.
It would be great if this command could be launched automatically if there was a dev dependency to build_runner
in the pubspec.yaml
file.
This feature should be enabled with a setting, in order to let people decide if want to activate it or not.
What do you think about this?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:16
- Comments:31 (15 by maintainers)
Top Results From Across the Web
build_runner - Dart
The build_runner package provides general-purpose commands for generating files, including testing the generated files or serving both source and generated ...
Read more >flutter pub run build_runner build failed - dart - Stack Overflow
I tried with many solutions, But error not gone. flutter packages pub run build_runner watch command ran with endless log.
Read more >build_runner | Dart Package - Pub.dev
Standalone generator and watcher for Dart using package:build . The build_runner package provides a concrete way of generating files using Dart code, outside ......
Read more >Dart build_runner - Visual Studio Marketplace
Automatically identify Packages with build_runner dependencies in the workspace. Log printing is completely independent when running multiple ...
Read more >Integrating Dart's Build Runner with VSCode
Launching Build Runner; Writing Task for Build Runner; Running a Task After File Save ... flutter pub run build_runner build lib/ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve got something basic working here that contributes
build_runner
tasks for projects that referencebuild_runner
in the pubspec. It’d be good to get some testing of it if anyone would like to give it a try.Grab this file, unzip it (I can’t attach vsix files here!), then run
Extensions: Install from VSIX
from the VS Code command palette and browse to it, then reload. (Note: you’ll automatically be upgraded to v2.20 stable when I publish it, so this functionality may vanish then, depending on whether this work gets merged into it - which depends on testing/feedback!)dart-code-2.20.0-beta.1.with-build-runner.vsix.zip
Then set the
dart.previewBuildRunnerTasks
setting totrue
in your VS Code settings.With this done, if you run the
Run Task
command from the VS Code command palette, you should see somebuild_runner
tasks (note: this requires that your project is a workspace root in VS Code, it won’t work for projects in sub-folders):If you have multiple roots that match, the workspace folder names will appear alongside the task names.
If you run
watch
(for ex.) then it’ll run the task and showBuilding...
in the status bar. Once the initial build finishes, theBuilding...
should vanish. When you trigger a rebuild (eg. by editing a file), you should seeBuilding...
reappear in the status bar for the duration of the build. You can click the little spanner/screwdriver icon in the status bar to jump to the command output.If you want this to run automatically, you can add this as a
preLaunchTask
inlaunch.json
(in future maybe this will be automatic, but for now it’s opt-in):With this set, when you hit F5 to try and run the project, it’ll first run
build_runner watch
. Once it sees the build has completed, it’ll launch the app.build_runner
will continue to run in the background, and on subsequent presses of F5 it’ll wait for any in-progress builds and then launch.It should(!) run the correct command (Flutter vs Pub) based on your project type automatically, so this should be testable with either.
Note: It’s not currently possible to customise the command (such as adding args), please 👍 this issue to support this.
Please try it out if you can, and post feedback!
For anyone who stumbles here through Google. This is now documented: https://dartcode.org/docs/tasks/