Hey there. I was able to successfully get Materialize’s SCSS files working in my theme but I’ve really been struggling with getting the JS files set up in Webpack.
Following the instructions here (https://github.com/roots/docs/blob/sage-9/sage/theme-development-and-building.md), I tried:
yarn install materialize-css
- In main.js, I added
import 'materialize-css/dist/js/materialize';
on line 3. - Ran
yarn run build
That seemed to work okay, but there was no directory in dist like the docs said “The dist folder will contain a _/node_modules/ directory that has any assets referenced from your packages.” And when I added the following to the finalize function wrapper in common.js, all hell broke loose:
Materialize.scrollFire([
{selector: 'img.lazyload', offset: 500, callback: function(el) {
Materialize.fadeInImage($(el));
}},
]);
All hell = the error message 'Materialize' is not defined.
Based on @ben’s advice here (Import WOW.js not working correctly with sage 9 - #2 by benword), I tried importing Materialize into the top of the common.js file. Here’s what I tried, and the corresponding errors I got:
import Materialize from 'materialize-css/dist/js/materialize.js';
Resulting error: common.js:15 Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_0_materialize_css_dist_js_materialize_js___default.a.scrollFire is not a function
import Materialize from 'materialize-css';
Resulting error: common.js:15 Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_0_materialize_css___default.a.scrollFire is not a function
Thanks for any help you can give me! I’m stumped!