Skip to content

Instantly share code, notes, and snippets.

@mumoc
Created February 16, 2021 03:26
Show Gist options
  • Save mumoc/2b1a65ae54d216639d340dfe292adb36 to your computer and use it in GitHub Desktop.
Save mumoc/2b1a65ae54d216639d340dfe292adb36 to your computer and use it in GitHub Desktop.
Lotties with Rails 6 and Webpacker
  1. Install Lottie Player:
npm install --save @lottiefiles/lottie-player
  1. Require it at app/javascript/packs/application.js
require('@lottiefiles/lottie-player');
  1. Set webpacker to load jsons
static_asset_extensions:
  - .json

extensions:
  - .json
  1. Put your lotties jsons wherever you want (e.g. app/javascript/images/lotties

  2. Render lottie-player tag in your html:

#my-lottie-container
  %lottie-player{ autoplay: true, loop: true, src: asset_pack_path('media/images.lotties/mylottie.json') }
  1. Profit

Extra:

  • Create a view helper to handle your lotties paths:
def lottie_pack_path(name)
  asset_pack_path "media/images/lotties/#{name}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment