Hot reloader for Dart
[HotReloader] lets the application hot reload itself on modifications to desired files.
main() async {
final reloader = new HotReloader();
reloader.addPath('.');
await reloader.go();
// TODO your code here!
}
[HotReloader] requires that VM service is enabled during program run for reloading to work. To enable VM services supply
either --enable-vm-service
or --observe
command line flag when the application is run.
Failing to do so will result in notHotReloadable
exception.
More information can be found at Dart VM
When there are too many changes, it is not efficient to reload the application for every change. Debouncing allows
[HotReloader] to reload only once every specified interval. debounceInterval
defaults to once every second.
main() async {
final reloader = new HotReloader(debounceInterval: const Duration(seconds: 10));
reloader.addPath('.');
await reloader.go();
// TODO your code here!
}
addPath
method shall be used to register file/directory path as [String].
main() async {
final reloader = new HotReloader();
reloader.addPath('lib/');
await reloader.go();
// Your code goes here
}
addGlob
shall be used to register multiple files/directories using a [Glob].
main() async {
final reloader = new HotReloader();
reloader.addGlob(new Glob('jaguar_*/lib'));
await reloader.go();
// Your code goes here
}
addFile
shall be used to register a FileSystemEntity
.
main() async {
final reloader = new HotReloader();
reloader.addFile(new File('pubspec.yaml'));
await reloader.go();
// Your code goes here
}
addUri
shall be used to register a path using an instance of [Uri].
main() async {
final reloader = new HotReloader();
reloader.addUri(new Uri(scheme: 'file', path: '/usr/lib/dart'));
await reloader.go();
// Your code goes here
}
addPackagePath
shall be used to register a path using package uri.
main() async {
final reloader = new HotReloader();
await reloader.addPackagePath(new Uri(scheme: 'package', path: 'jaguar/'));
await reloader.go();
// Your code goes here
}
addPackageDependencies
shall be used to register all packages the current package depends on.
main() async {
final reloader = new HotReloader();
await reloader.addPackageDependencies();
await reloader.go();
// Your code goes here
}
reload
method is publicly available to request for application reload when desired.
onChange
stream is fired every time there is a change in the registered file paths.
onReload
stream is fired after the application is reloaded irrespective of whether the file change or the user triggered
the reload.