How can I enable and use a custom JavaScript file in Magento 2?
I have a theme.js
file located at app/design/frontend/<Vendor>/<theme>/web/js
and it depends on jQuery. Now I know there are two possible methods for inclusion, via the recommend RequireJS method or directly from within default_head_blocks.xml
.
Now, I believe best practice would be to use RequireJS, but I am unfamiliar with this tool and I'm struggling a bit being able to get my theme.js included. Could someone point me in the right direction, please? I've read the documentation, but I'm still unable to grasp the concept properly at this stage and I cannot get it to work.