shelf_hotreload 1.3.0 icon indicating copy to clipboard operation
shelf_hotreload: ^1.3.0 copied to clipboard

Wrapper to easily enable hot-reload for shelf applications.

shelf_hotreload #

Wrapper to easily enable hot-reload for shelf applications.

Usage #

import 'dart:io';

import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_hotreload/shelf_hotreload.dart';

// Run this app with --enable-vm-service (or use debug run)
void main() async {
  withHotreload(() => createServer());
}

Future<HttpServer> createServer() {
  handler(shelf.Request request) => shelf.Response.ok('hot!');
  return io.serve(handler, 'localhost', 8080);
}

In order to enable hot-reload, you need to run your Dart application with --enable-vm-service (or use debug run in your IDE).

For example:

dart run --enable-vm-service path/to/app.dart

Custom logging #

You can also also modify the default logging by providing callbacks:

final myLogger = Logger();

withHotreload(
  () => createServer(),
  onReloaded: () => myLogger.log('Reload!'),
  onHotReloadNotAvailable: () => myLogger.log('No hot-reload :('),
  onHotReloadAvailable: () => myLogger.log('Yay! Hot-reload :)'),
  onHotReloadLog: (log) => myLogger.log('Reload Log: ${log.message}'),
  logLevel: Level.INFO,
);
35
likes
130
pub points
84%
popularity

Publisher

verified publisher iconfelix-blaschke.de

Wrapper to easily enable hot-reload for shelf applications.

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

hotreloader, intl, logging

More

Packages that depend on shelf_hotreload