How do I run commands after build.dart builds?

Issue

build.dart is run by Dart Editor whenever a file changes. Many developers use build.dart to compile their Web UI apps. How can I run other commands after Web UI compiler finishes?

Solution

The build() function returns a Future. You can register a callback to run after build() runs.

Here is an example:

import 'package:web_ui/component_build.dart';
import 'dart:io';
import 'dart:async';

void main() {
  var args = new List.from(new Options().arguments);
  args.addAll(['--', '--no-rewrite-urls']);

  Future dwc = build(args, ['web/clock_page.html']);

  dwc
    .then((_) => Process.run('cp', ['packages/browser/dart.js', 'web/out/dart.js']))
    .then((_) => Process.run('cp', ['App.css', 'out']));
}

Learn more:

Answered By – Seth Ladd

Answer Checked By – David Goodson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *