Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vegardit/dart-hotreloader
Automatic hot code reloader for Dart projects.
https://github.com/vegardit/dart-hotreloader
dart dart-library dart-package dart-vm dartlang hot-reload hotreloader
Last synced: about 5 hours ago
JSON representation
Automatic hot code reloader for Dart projects.
- Host: GitHub
- URL: https://github.com/vegardit/dart-hotreloader
- Owner: vegardit
- License: apache-2.0
- Created: 2020-04-07T15:39:04.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-01-20T17:14:05.000Z (about 1 month ago)
- Last Synced: 2025-02-13T13:14:30.262Z (7 days ago)
- Topics: dart, dart-library, dart-package, dart-vm, dartlang, hot-reload, hotreloader
- Language: Dart
- Homepage: https://buymeacoffee.com/vegardit
- Size: 122 KB
- Stars: 53
- Watchers: 5
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# hotreloader (Dart)
[](https://github.com/vegardit/dart-hotreloader/actions?query=workflow%3ABuild)
[](LICENSE.txt)
[](https://pub.dev/packages/hotreloader)
[](CODE_OF_CONDUCT.md)1. [What is it?](#what-is-it)
1. [Requirements](#requirements)
1. [How to use](#how-to-use)
1. [Logging](#logging)
1. [Alternatives](#alternatives)
1. [Changelog / Version History](#changelog)
1. [License](#license)This [Dart](https://dart.dev) 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](https://github.com/dart-lang/sdk/wiki/Hot-reload) capabilities to the running Dart process.hotreloader 4.x requires [Dart SDK](https://dart.dev/get-dart) **3.0.0** or higher.
hotreloader 3.x requires [Dart SDK](https://dart.dev/get-dart) **2.12.0** or higher.
hotreloader 1.x-2.x requires [Dart SDK](https://dart.dev/get-dart) **2.6.0** or higher.
1. Add hotreloader to your dev dependencies using this command
```sh
dart pub add --dev hotreloader
```or by adding this to your `pubspec.yaml`:
```yaml
dev_dependencies:
hotreloader: ^4.3.0
```1. Enable hot reloading in your entry point dart file, e.g. `bin/main.dart`
```dart
import 'package:hotreloader/hotreloader.dart';Future main(List 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();
}
```1. Run the dart program using the Dart VM with the `--enable-vm-service` flag enabled, e.g.
```bash
dart --enable-vm-service bin/main.dart
```1. You can now change dart files under the `lib` and the changes should be applied to the running process.
The reloader service can be further customized, e.g.
```dart
import 'package:hotreloader/hotreloader.dart';Future main(List 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();
}
```This library uses the [logging](https://pub.dev/packages/logging) package for logging.
You can configure the logging framework and change the [log-level](https://github.com/dart-lang/logging/blob/master/lib/src/level.dart) programmatically like this:
```dart
import 'dart:io' as io;
import 'dart:isolate';
import 'package:hotreloader/hotreloader.dart';
import 'package:logging/logging.dart' as logging;Future 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();
}
```- 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](CHANGELOG.md) and adheres to [Semantic Versioning](https://semver.org) and [Keep a CHANGELOG](https://keepachangelog.com)
All files are released under the [Apache License 2.0](LICENSE.txt).
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/.