Elixir CDN Assets Manager

Content Delivery Network Package for Elixir/Phoenix.

This package provides the developer the ability to upload assets to a CDN with single mix command.
Inspired by Vinelab/cdn.

Installation

If available in Hex, the package can be installed as:

  1. Add cdn to your list of dependencies in mix.exs:
{:cdn, "~> 0.0.1"}

Configuration

Firstly this package is relies on ex_aws then setting ex_aws before configuration.

config :ex_aws,
  region: "us-east-1"

After that Configure your config.exs like this.

config :cdn,  bucket: "",
              include: [
                directories: ["priv/static", "public/bin"],
                patterns: ["**/*", "**/*.css"],
                hidden: true
              ],
              exclude: [
                directories: [],
                patterns: [],
                hidden: true
              ],
              acl: :public_read,
              cloudfront_url: "https://asset.s3.amazonaws.com",
              bypass: false

Usage

Commands

mix cdn.push
mix cdn.empty

Asset Helper

Import CDN Helper to your dependency

web.ex

def view do
  quote do
    ...
    # Import CDN helper
    import Cdn.Helper
    ...
  end
end

then you can load static file like this.

<%= cdn(static_path(@conn, "/css/app.css")) %>

# MIX_ENV=dev
<%= cdn(static_path(@conn, "/css/app.css")) %> #=> "/css/app.css"

# MIX_ENV=prod
<%= cdn(static_path(@conn, "/css/app.css")) %> #=> "https://assets.cloudfront.net/css/app.css"

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request