https://github.com/pta2002/gleam-radiate
Hot code reloading for Gleam
https://github.com/pta2002/gleam-radiate
gleam
Last synced: 5 months ago
JSON representation
Hot code reloading for Gleam
- Host: GitHub
- URL: https://github.com/pta2002/gleam-radiate
- Owner: pta2002
- License: apache-2.0
- Created: 2023-10-21T17:10:26.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-09-18T10:34:06.000Z (9 months ago)
- Last Synced: 2025-09-18T12:41:38.507Z (9 months ago)
- Topics: gleam
- Language: Gleam
- Homepage:
- Size: 32.2 KB
- Stars: 56
- Watchers: 3
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# radiate
[](https://hex.pm/packages/radiate)
[](https://hexdocs.pm/radiate/)
Hot reloading while in development for Gleam!
## Introduction
Radiate will watch any directory you specify for changes. When a file is
changed in that directory, it'll check if it's a Gleam file, and if it is, the
project will be recompiled and all modified modules will be reloaded, without
having to restart the BEAM VM.
## Quick start
```gleam
// On main.gleam
import gleam/erlang/process
import gleam/io
import radiate
import message
pub fn main() {
let _ =
radiate.new()
|> radiate.add_dir("src")
|> radiate.start()
let timer_subject = process.new_subject()
print_every_second(timer_subject)
}
fn print_every_second(subject: process.Subject(Nil)) {
process.send_after(subject, 1000, Nil)
let _ = process.receive(subject, 1500)
io.println(message.get_message())
print_every_second(subject)
}
// On message.gleam
pub fn get_message() -> String {
"Hello!"
}
```
When you first run this, it'll print "Hello!" every second.
Now, go ahead and change the text `get_message` returns to `"Hello, world!"`, and save the file.
As soon as you save, the message printed is changed to "Hello, world!", without needing to restart the program!
### Warning for macOS users
Right now, the `add_dir` function only supports `"."` or an absolute path! Be careful to resolve the path to get it work if you want to watch `"src"` for example.
## Adding a callback
You can add callbacks to be run every time code is reloaded through `on_reload`:
```gleam
import radiate
import gleam/io
pub fn main() {
let _ = radiate.new()
|> radiate.add_dir("src")
|> radiate.on_reload(fn (_state, path) {
io.println("Change in " <> path <> ", reloading!")
})
|> radiate.start()
}
```
## Installation
This package can be added to your Gleam project:
```sh
gleam add radiate
```
and its documentation can be found at .