Viewing version 2.0.1. Open the latest package page.
hotreloader
2.0.1Automatic hot code reloader for Dart projects.
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
Dart SDK 2.6.0 or higher.
How to use
-
Add this to your
pubspec.yamldev_dependencies: hotreloader: ^2.0.0 -
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
- https://pub.dev/packages/jaguar_hotreload
- https://pub.dev/packages/recharge
- https://pub.dev/packages/reloader
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]
[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:2.0.1'pubspec.yaml
# https://dart.dev/tools/pub/pubspec
name: hotreloader
version: 2.0.1
description: Automatic hot code reloader for Dart projects.
repository: https://github.com/vegardit/dart-hotreloader
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.6.0 <3.0.0'
# https://dart.dev/tools/pub/dependencies#version-constraints
dependencies:
logging: ^0.11.3+2 # https://pub.dev/packages/logging
path: ^1.6.3 # https://pub.dev/packages/path
stream_transform: ^1.0.0 # https://pub.dev/packages/stream_transform
vm_service: ^4.0.0 # https://pub.dev/packages/vm_service
watcher: ^0.9.7+10 # https://pub.dev/packages/watcher
dev_dependencies:
lint: ^1.0.0
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
logging "^0.11.3+2"
path "^1.6.3"
stream_transform "^1.0.0"
vm_service "^4.0.0"
watcher "^0.9.7+10"