Viewing version 3.0.5. Open the latest package page.
hotreloader
3.0.5Automatic hot code reloader for Dart projects that monitors the source files of a Dart project for changes and automatically applies them to the running Dart process.
Readme
hotreloader (Dart)
Build Status License Pub Package Contributor Covenant
What is it?
This Dart library provides a code reloading service that monitors the source files of a Dart project on the local file system for changes and automatically applies them using the Dart VM's hot reload capabilities to the running Dart process.
Requirements
hotreloader 1.x-2.x requires Dart SDK 2.6.0 or higher.
hotreloader 3.x requires Dart SDK 2.12.0 or higher.
How to use
-
Add hotreloader to your dev dependencies using this command
dart pub add --dev hotreloaderor by adding this to your
pubspec.yaml:dev_dependencies: hotreloader: ^3.0.4 -
Enable hot reloading in your entry point dart file, e.g.
bin/main.dartimport 'package:hotreloader/hotreloader.dart'; Future<void> main(List<String> args) async { // instantiate a reloader that by monitors the project's source code folders for changes final reloader = await HotReloader.create(); // ... your other code // cleanup reloader.stop(); } -
Run the dart program using the Dart VM with the
--enable-vm-serviceflag enabled, e.g.dart --enable-vm-service bin/main.dart -
You can now change dart files under the
liband the changes should be applied to the running process.
The reloader service can be further customized, e.g.
import 'package:hotreloader/hotreloader.dart';
Future<void> main(List<String> args) async {
final reloader = await HotReloader.create(
debounceInterval: Duration(seconds: 2), // wait up to 2 seconds after file change before reloading
onBeforeReload: (ctx) =>
ctx.isolate.name != 'foobar' && // never reload the isolate named 'foobar'
ctx.event?.path.contains('/mymodel/')) ?? true, // only perform reload when dart files under ../mymodel/ are changed
onAfterReload: (ctx) => print('Hot-reload result: ${ctx.result}')
);
// ... your other code
await reloader.reloadCode(); // programmatically trigger code reload
// ... your other code
// cleanup
reloader.stop();
}
Logging
This library uses the logging package for logging.
You can configure the logging framework and change the log-level programmatically like this:
import 'dart:io' as io;
import 'dart:isolate';
import 'package:hotreloader/hotreloader.dart';
import 'package:logging/logging.dart' as logging;
Future<void> main() async {
logging.hierarchicalLoggingEnabled = true;
// print log messages to stdout/stderr
logging.Logger.root.onRecord.listen((msg) =>
(msg.level < logging.Level.SEVERE ? io.stdout : io.stderr)
.write('${msg.time} ${msg.level.name} [${Isolate.current.debugName}] ${msg.loggerName}: ${msg.message}\n')
);
HotReloader.logLevel = logging.Level.CONFIG;
final reloader = await HotReloader.create();
// ... your other code
// cleanup
reloader.stop();
}
Alternatives
- https://pub.dev/packages/angel_hot (last update 05/2019)
- https://pub.dev/packages/jaguar_hotreload (last update 02/2019)
- https://pub.dev/packages/recharge
- https://pub.dev/packages/reloader (last update 01/2019)
Changelog / Version History
This project maintains a changelog and adheres to Semantic Versioning and Keep a CHANGELOG
License
All files are released under the Apache License 2.0.
Individual files contain the following tag instead of the full license text:
SPDX-License-Identifier: Apache-2.0
This enables machine processing of license information based on the SPDX License Identifiers that are available here: https://spdx.org/licenses/.
Changelog
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[Unreleased]
[3.0.5] - 2022-07-11
Changed
- support vm_service 9.x
[3.0.4] - 2022-04-25
Fixed
- #9 multiple directories starting with same characters are not watched
[3.0.3] - 2022-03-20
Fixed
- #6 Awaiting HotReloader.stop() causes program to wait forever
Changed
- support vm_service 8.x
[3.0.2] - 2022-01-04
Changed
- support vm_service 7.x
[3.0.1] - 2021-04-18
Changed
- improve file watching
- replace some sync calls with async calls
[3.0.0] - 2021-03-16
Added
- enable null safety support
Changed
- require Dart 2.12.0 for null safety support
- upgrade dependencies:
- logging 1.0.0
- path 1.8.0
- stream_transform 2.0.0
- vm_service 6.1.0+1
- watcher 1.0.0
[2.0.2] - 2020-10-19
Added
- support version 5.x of vm_service library
[2.0.1] - 2020-10-18
Fixed
FormatException: Scheme not starting with alphabetic characterwith Dart 2.9 or higher
[2.0.0] - 2020-04-09
Added
- watch dependencies for source code changes
Changed
- support slightly older versions of dependencies
[1.0.0] - 2020-04-08
- initial release
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'hotreloader:3.0.5'pubspec.yaml
# https://dart.dev/tools/pub/pubspec
name: hotreloader
version: 3.0.5
description: >
Automatic hot code reloader for Dart projects that monitors the source files of a Dart
project for changes and automatically applies them to the running Dart process.
repository: https://github.com/vegardit/dart-hotreloader.git
homepage: https://github.com/vegardit/dart-hotreloader
documentation: https://github.com/vegardit/dart-hotreloader/blob/master/README.md
issue_tracker: https://github.com/vegardit/dart-hotreloader/issues
environment:
# https://dart.dev/tools/pub/pubspec#sdk-constraints
sdk: ">=2.12.0 <3.0.0"
# https://dart.dev/tools/pub/dependencies#version-constraints
dependencies:
collection: ^1.15.0 # https://pub.dev/packages/collection
logging: ^1.0.0 # https://pub.dev/packages/logging
path: ^1.8.0 # https://pub.dev/packages/path
stream_transform: ^2.0.0 # https://pub.dev/packages/stream_transform
vm_service: ">=6.0.1 <10.0.0" # https://pub.dev/packages/vm_service
watcher: ^1.0.0 # https://pub.dev/packages/watcher
dev_dependencies:
lint: ^1.5.3
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 1.0.0 | Cached · Upstream SHA-256 matched | Download | 6b1f04e0…2d32ea |
| 2.0.0 | Cached · Upstream SHA-256 matched | Download | 5a8af98c…1b24fb |
| 2.0.1 | Cached · Upstream SHA-256 matched | Download | 16146cf5…4f5d6e |
| 2.0.2 | Cached · Upstream SHA-256 matched | Download | 5a14de78…96bfbf |
| 3.0.0 | Cached · Upstream SHA-256 matched | Download | eb6b4993…2595c5 |
| 3.0.1 | Cached · Upstream SHA-256 matched | Download | c2eca005…faad13 |
| 3.0.2 | Cached · Upstream SHA-256 matched | Download | 15f360e8…b152a2 |
| 3.0.3 | Cached · Upstream SHA-256 matched | Download | 90bb3ae5…d66ad0 |
| 3.0.4 | Cached · Upstream SHA-256 matched | Download | 906f8180…f6da28 |
| 3.0.5 | Cached · Upstream SHA-256 matched | Download | 66b78edf…28e0b8 |
| 3.0.6 | Cached · Upstream SHA-256 matched | Download | 728c0613…e6dacf |
| 4.0.0 | Cached · Upstream SHA-256 matched | Download | 6c61cfa8…926da6 |
| 4.1.0 | Cached · Upstream SHA-256 matched | Download | 94ee21a6…231449 |
| 4.2.0 | Cached · Upstream SHA-256 matched | Download | ed56fdc1…d9158e |
| 4.3.0 | Cached · Upstream SHA-256 matched | Download | bc167a11…e5734b |
| 4.4.0 | Cached · Upstream SHA-256 matched | Download | 66871df4…3c4ebf |
Dependencies
collection "^1.15.0"
logging "^1.0.0"
path "^1.8.0"
stream_transform "^2.0.0"
vm_service "\u003e=6.0.1 \u003c10.0.0"
watcher "^1.0.0"