This guide explains how to work with webpacker and specifically how to add jquery:
https://www.botreetechnologies.com/blog/introducing-jquery-in-rails-6-using-webpacker
And then this guide shows how to add custom javascript code:
https://dev.to/morinoko/adding-custom-javascript-in-rails-6-1ke6
If you want to use coffeescript, you can add coffee script to the javascript asset pipeline by following this guide:
https://bloggie.io/@kinopyo/rails-enable-coffeescript-with-webpacker