This might also work or Rails 5.1, but I haven’t tried that yet.
Add the webpacker gem to your Gemfile:
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker'
Then run (assuming you’re on macOS and using Homebrew):