I've been trying to add npm packages to my Laravel project by using the commands npm install
and npm install masonry-layout
. After running npm run watch
, I can see the package in my node_modules folder.
In an attempt to integrate the package into my project, I added require('masonry-layout');
to my app.js file. Additionally, I tried adding
window.anything = require('masonry-layout');
or window._ = require('masonry-layout');
to my bootstrap.js file. In my view, I called the function as follows:
var $grid = $('.grid').imagesLoaded( function() {
$grid.masonry({
itemSelector: '.grid-item',
columnWidth: '.grid-sizer',
percentPosition: true,
isResizable: true,
transitionDuration: '0.8s',
isAnimated: true
});
});
This is what my app.js looks like:
require('./bootstrap');
require('masonry-layout');
require('imagesloaded');
And here is the content of my bootstrap.js file:
window._ = require('lodash');
window.anything = require('masonry-layout');
window.anything = require('imagesloaded');
// Remaining code omitted for brevity
Despite also installing imagesLoaded, it doesn't seem to be working. Only when I include the cdn link directly in my view does it work properly. Can someone help me identify what I am doing wrong?