I recently installed a NPM Package, Masonry, to my WordPress project. I would like to use it, but I am not sure where I should add the script.
I was thinking of adding it via functions.php where I will enqueue it and find it in my node_modules folder using
get_template_directory_uri() . /node_modules/masonry-layout/dist/masonry.pkgd.min.js
But I feel there should be a simpler/better way.
I have bootstrap installed, and in my local js file, I have
require('bootstrap');
I then have a webpack mix that takes mixes all the js files I have and adds it to my /dist
Is there a similar way to add it to my package without having to use functions.php enqueue it? I would love to only have one js script enqueued rather than having several one. (Unless you think that is bad practice).
Something similar to:
require('masonry');
Additionally, please don't try to persuade me to use the CDN instead.
Here is the package: https://www.npmjs.com/package/masonry-layout