Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/praveenperera/gleam_compile
Tiny hex package to make the development experience of using gleam in elixir (and especially phoenix projects) better.
https://github.com/praveenperera/gleam_compile
autoreload elixir gleam hex phoenix
Last synced: 23 days ago
JSON representation
Tiny hex package to make the development experience of using gleam in elixir (and especially phoenix projects) better.
- Host: GitHub
- URL: https://github.com/praveenperera/gleam_compile
- Owner: praveenperera
- License: apache-2.0
- Created: 2020-07-12T02:57:08.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-02-21T13:12:44.000Z (over 2 years ago)
- Last Synced: 2024-10-12T05:05:37.206Z (about 1 month ago)
- Topics: autoreload, elixir, gleam, hex, phoenix
- Language: Elixir
- Homepage:
- Size: 472 KB
- Stars: 28
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Elixir + Gleam = ❤️
---
## Description
A tiny hex package makes it easier to use [gleam](https://github.com/gleam-lang/gleam) in elixir and phoenix projects
This package does two things
1. Runs the gleam compiler
2. In development it automatically reloads the gleam files when recompiled**Demo with Phoenix Live Reload**
## Installation
**_Note: Make sure [gleam is already installed on your system](https://gleam.run/getting-started/installing-gleam.html)._**
This package is available on [hex](https://hex.pm/packages/gleam_compile).
1. The package can be installed by adding `gleam_compile` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:gleam_compile, "~> 0.2.0"}
]
end
```2. Add `:gleam` to list of compilers, and the gleam folders to the `erlc_paths`
in your `mix.exs````diff
def project do
[
app: :jib,
version: "0.1.0",
elixir: "~> 1.5",
elixirc_paths: elixirc_paths(Mix.env()),
+ erlc_paths: ["src", "gen"],
+ compilers: [:gleam] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
releases: releases(),
aliases: aliases(),
deps: deps()
]
end
```## Integrating with Phoenix Live Reloader
1. Add `:gleam` to list of compilers in your `mix.exs`
```elixir
compilers: [:phoenix, :gettext, :gleam] ++ Mix.compilers()
``````diff
def project do
[
app: :jib,
version: "0.1.0",
elixir: "~> 1.5",
elixirc_paths: elixirc_paths(Mix.env()),
erlc_paths: ["src", "gen"],
- compilers: [:phoenix, :gettext] ++ Mix.compilers(),
+ compilers: [:phoenix, :gettext, :gleam] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
releases: releases(),
aliases: aliases(),
deps: deps()
]
end
```2. In `dev.exs` add this line in the `Endpoint` config
```elixir
reloadable_compilers: [:gettext, :phoenix, :elixir, :gleam],
``````diff
config :my_app, MyAppWeb.Endpoint,
http: [port: 4000],
debug_errors: true,
code_reloader: true,
check_origin: false,
+ reloadable_compilers: [:gettext, :phoenix, :elixir, :gleam],
watchers: [
node: [
"node_modules/webpack/bin/webpack.js",
"--mode",
"development",
"--watch-stdin",
cd: Path.expand("../assets", __DIR__)
]
]
```3. Add gleam files to the live_reload patterns
```elixir
~r"src/.*(gleam)$",
``````diff
config :my_app, MyAppWeb.Endpoint,
live_reload: [
patterns: [
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
~r"priv/gettext/.*(po)$",
+ ~r"src/.*(gleam)$",
~r"lib/jib_web/{live,views}/.*(ex)$",
~r"lib/jib_web/templates/.*(eex)$"
]
]
```## Acknowledgements
- [Mixing Gleam & Elixir](https://dev.to/contact-stack/mixing-gleam-elixir-3fe3) – by [Michael Jones](https://twitter.com/michaelpjones)
- [Louis](https://twitter.com/louispilfold) (creator of gleam) for [talking me through the process](https://twitter.com/PraveenPerera/status/1281696372954206208) and [helping with debugging](https://twitter.com/PraveenPerera/status/1281692313308340225)## License
GleamCompile is released under the Apache License 2.0 - see the [LICENSE](LICENSE.md) file.