Search code examples
ruby-on-railsrubywebpackerplyr.js

How to implement plyr.js within a Rails 6 site?


https://plyr.io/ is a javascript library to play videos with support for YouTube and Vimeo. I'm trying to implement it within a Rails 6 site. What are the steps to make this happen?


Solution

  • Rails 6 using webpacker to manage their assets, to install plyr you just need install it through package manager:

    yarn add plyr
    

    then you can require it in your js file like the docs:

    import Plyr from 'plyr';
     
    const player = new Plyr('#player');
    

    make sure you have run webpacker dev server, if not you may getting module not found. Hope this help, correct me if there is any mistake.