pub repository
mirror.p-hatan.comhotreloader
4.4.0Automatic 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 4.x requires Dart SDK 3.0.0 or higher.
hotreloader 3.x requires Dart SDK 2.12.0 or higher.
hotreloader 1.x-2.x requires Dart SDK 2.6.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: ^4.3.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 (last update 05/2019)
- https://pub.dev/packages/jaguar_hotreload (last update 02/2019)
- https://pub.dev/packages/recharge (last update 04/2022)
- 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]
[4.4.0] - 2026-04-05
Added
[4.3.0] - 2025-01-20
Changed
- support vm_service 15.x
[4.2.0] - 2024-02-12
Changed
- support vm_service 14.x
[4.1.0] - 2023-10-26
Changed
- support vm_service 12.x and 13.x
[4.0.0] - 2023-09-18
Changed
- require/support Dart 3.0.0 or higher
[3.0.6] - 2023-04-03
Changed
- support vm_service 11.x
[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.com
flutter pub add hotreloaderpubspec.yaml
# https://dart.dev/tools/pub/pubspec
name: hotreloader
version: 4.4.0
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: ">=3.0.0 <4.0.0"
# https://dart.dev/tools/pub/dependencies#version-constraints
dependencies:
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 <16.0.0" # https://pub.dev/packages/vm_service
watcher: ^1.1.0 # https://pub.dev/packages/watcher
dev_dependencies:
lint: ^2.1.2
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 1.0.0 | 2020-04-08T09:43:14.716851Z | Download | 6b1f04e0318514481fe60394b2176c56817c85f01f43b82ee36d3badef2d32ea |
| 2.0.0 | 2020-04-09T15:17:27.254927Z | Download | 5a8af98cbca2223c37c4b2e2bd9bcd3be4cec421d6e3540b19af0ba99a1b24fb |
| 2.0.1 | 2020-10-18T18:47:24.629194Z | Download | 16146cf5ebfc1ce4c9f80feecd268b174c260d1c64c2fd23f1255d5c094f5d6e |
| 2.0.2 | 2020-10-19T17:37:21.043652Z | Download | 5a14de7814bfbeded507913d24ada6d32337f41ec13c708b0bbad23f1c96bfbf |
| 3.0.0 | 2021-03-16T22:15:30.870092Z | Download | eb6b4993cb0b67264bc42982dac7291fe01109d7094b185e73ae6dc1bb2595c5 |
| 3.0.1 | 2021-04-18T12:47:25.910393Z | Download | c2eca0055f0c3cde6a9d775e624bbdf99d2eb68d0b283bd01cecb76155faad13 |
| 3.0.2 | 2022-01-04T18:51:23.144850Z | Download | 15f360e86e4f6056b6bd4426c7a9d376ccd6cf6873e90d60c758c1319ab152a2 |
| 3.0.3 | 2022-03-20T20:24:25.992763Z | Download | 90bb3ae5d72cc87b6251da956958a47b49914a5732736671089f7e6febd66ad0 |
| 3.0.4 | 2022-04-25T09:51:20.385023Z | Download | 906f81803b6e81d9908e95fac387daa5a6ba779ff494b438f0c82eca16f6da28 |
| 3.0.5 | 2022-07-11T12:00:54.957662Z | Download | 66b78edf340352fcdd2043ab6116e58ec018c5968cab6485cde0f1769d28e0b8 |
| 3.0.6 | 2023-04-03T13:30:12.804535Z | Download | 728c0613556c1d153f7e7f4a367cffacc3f5a677d7f6497a1c2b35add4e6dacf |
| 4.0.0 | 2023-09-18T20:17:06.259881Z | Download | 6c61cfa809dc9d35ab759c3a4fb96548d699103ee9c5b9412b90c8b770926da6 |
| 4.1.0 | 2023-10-26T17:15:34.485449Z | Download | 94ee21a60ea2836500799f3af035dc3212b1562027f1e0031c14e087f0231449 |
| 4.2.0 | 2024-02-12T11:44:24.973660Z | Download | ed56fdc1f3a8ac924e717257621d09e9ec20e308ab6352a73a50a1d7a4d9158e |
| 4.3.0 | 2025-01-20T17:13:18.345881Z | Download | bc167a1163807b03bada490bfe2df25b0d744df359227880220a5cbd04e5734b |
| 4.4.0 | 2026-04-04T22:53:18.913943Z | Download | 66871df468fc24eee81f1a0a7cb98acc104716f9b7376d355437b48d633c4ebf |
Dependencies
logging "^1.0.0"
path "^1.8.0"
stream_transform "^2.0.0"
vm_service "\u003e=6.0.1 \u003c16.0.0"
watcher "^1.1.0"