Skip to content

coingaming/phoenix_view_assets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PhoenixViewAssets

Deprecated: use https://hex.pm/packages/asset_import package instead.

Helps to manage view specific assets in phoenix project. Uses automatic code splitting to avoid over-fetching or downloading assets twice, if they are used in multiple views. Also supports phoenix live reload.

Installation

Add phoenix_view_assets to your list of dependencies in mix.exs:

def deps do
  [
    {:phoenix_view_assets, "~> 0.1"}
  ]
end

Use (or merge) example_assets for assets/ in your project.

Setup

  1. Create module MyAppWeb.Assets:
defmodule MyAppWeb.Assets do
  use PhoenixViewAssets
end
  1. Use MyAppWeb.Assets in your layout view to generate scripts and styles functions in compile time.
defmodule MyAppWeb.LayoutView do
  use MyAppWeb, :view
  use MyAppWeb.Assets
end
  1. Use styles and scripts functions generated by MyAppWeb.Assets to add assets to your layout:
<head>
  ...
  <%= for path <- styles(@conn) do %>
    <link rel="stylesheet" href="<%= path %>" />
  <% end %>
</head>
<body>
  ...
  <%= for path <- scripts(@conn) do %>
    <script type="text/javascript" src="<%= path %>"></script>
  <% end %>
</body>