• Stars
    star
    289
  • Rank 137,979 (Top 3 %)
  • Language
    Elixir
  • License
    MIT License
  • Created about 9 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Provides live-reload functionality for Phoenix

A project for live-reload functionality for Phoenix during development.

Usage

You can use phoenix_live_reload in your projects by adding it to your mix.exs dependencies:

def deps do
  [{:phoenix_live_reload, "~> 1.3"}]
end

You can configure the reloading interval in ms in your config/dev.exs:

# Watch static and templates for browser reloading.
config :my_app, MyAppWeb.Endpoint,
  live_reload: [
    interval: 1000,
    patterns: [
      ...

The default interval is 100ms.

Backends

This project uses FileSystem as a dependency to watch your filesystem whenever there is a change and it supports the following operating systems:

  • Linux via inotify (installation required)
  • Windows via inotify-win (no installation required)
  • Mac OS X via fsevents (no installation required)
  • FreeBSD/OpenBSD/~BSD via inotify (installation required)

There is also a :fs_poll backend that polls the filesystem and is available on all Operating Systems in case you don't want to install any dependency. You can configure the :backend in your config/config.exs:

config :phoenix_live_reload,
  backend: :fs_poll

By default the entire application directory is watched by the backend. However, with some environments and backends, this may be inefficient, resulting in slow response times to file modifications. To account for this, it's also possible to explicitly declare a list of directories for the backend to watch (they must be relative to the project root, otherwise they are just ignored), and additional options for the backend:

config :phoenix_live_reload,
  dirs: [
    "priv/static",
    "priv/gettext",
    "lib/example_web/live",
    "lib/example_web/views",
    "lib/example_web/templates",
    "../another_project/priv/static", # Contents of this directory is not watched
    "/another_project/priv/static", # Contents of this directory is not watched
  ],
  backend: :fs_poll,
  backend_opts: [
    interval: 500
  ]

Skipping remote CSS reload

All stylesheets are reloaded without a page refresh anytime a style is detected as having changed. In certain cases such as serving stylesheets from a remote host, you may wish to prevent unnecessary reload of these stylesheets during development. For this, you can include a data-no-reload attribute on the link tag, ie:

<link rel="stylesheet" href="http://example.com/style.css" data-no-reload>

Differences between Phoenix.CodeReloader

Phoenix.CodeReloader recompiles code in the lib directory. This means that if you change anything in the lib directory (such as a context) then the Elixir code will be reloaded and used on your next request.

In contrast, this project adds a plug which injects some JavaScript into your page with a WebSocket connection to the server. When you make a change to anything in your config for live_reload (JavaScript, stylesheets, templates and views by default) then the page will be reloaded in response to a message sent via the WebSocket. If the change was to an Elixir file then it will be recompiled and served when the page is reloaded. If it is JavaScript or CSS, then only assets are reloaded, without triggering a full page load.

License

Same license as Phoenix.

More Repositories

1

phoenix

Peace of mind from prototype to production
Elixir
20,545
star
2

phoenix_live_view

Rich, real-time user experiences with server-rendered HTML
Elixir
5,741
star
3

phoenix_live_dashboard

Realtime dashboard with metrics, request logging, plus storage, OS and VM insights
Elixir
1,925
star
4

phoenix_pubsub

Distributed PubSub and Presence platform for the Phoenix Framework
Elixir
611
star
5

flame

Elixir
607
star
6

phoenix_guides

User guides for the Phoenix web development framework.
499
star
7

tailwind

An installer for tailwind
Elixir
461
star
8

phoenix_ecto

Phoenix and Ecto integration with support for concurrent acceptance testing
Elixir
437
star
9

phoenix_html

Building blocks for working with HTML in Phoenix
Elixir
379
star
10

firenest

Elixir
271
star
11

esbuild

An installer for esbuild
Elixir
261
star
12

phoenix_pubsub_redis

The Redis PubSub adapter for the Phoenix framework
Elixir
174
star
13

dns_cluster

Simple DNS clustering for distributed Elixir nodes
Elixir
162
star
14

vscode-phoenix

Syntax highlighting support for Phoenix templates in Visual Studio Code.
155
star
15

plds

CLI version of Phoenix LiveDashboard
Elixir
85
star
16

websock

A specification for Elixir apps to service WebSocket connections
Elixir
70
star
17

phoenix_view

View abstraction for Phoenix v1.0-v1.6
Elixir
64
star
18

tree-sitter-heex

HEEx grammer for Tree-sitter
JavaScript
48
star
19

phoenix_template

Template rendering for Phoenix
Elixir
48
star
20

ex_conf

Simple Elixir Configuration Management
Elixir
35
star
21

archives

Holds archives for released Phoenix versions
27
star
22

websock_adapter

Implementation of the WebSock specification for servers
Elixir
25
star
23

phoenix_site

CSS
13
star
24

phoenix_html_helpers

Collection of helpers to generate and manipulate HTML contents
Elixir
13
star
25

media

Phoenix Related Media
10
star
26

node_checker

Elixir
3
star