I am trying to add some new functionalities to every page/post with JS. But nothing shows, and I am not even sure is app.js loaded correctly.
My code:
// app.js
import {domReady} from '@roots/sage/client';
import ManageCart from '@scripts/components/ManageCart';
/**
* app.main
*/
const main = async (err) => {
if (err) {
// handle hmr errors
console.error(err);
}
/**
* ManageCart
* @type {ManageCart}
*/
const manageCart = new ManageCart();
manageCart.init();
};
/**
* Initialize
*
* @see https://webpack.js.org/api/hot-module-replacement
*/
domReady(main);
import.meta.webpackHot?.accept(main);
and
// ManageCart.js
/**
* Back to top button controller
*/
export default class ManageCart {
constructor() {
this.DOM = {
addToCart: ".js-add-to-cart"
}
this.addToCart = document.querySelectorAll(this.DOM.addToCart);
}
/**
* Init
*/
init() {
console.log("ManageCart init()");
if (this.addToCart.length > 0) {
console.log("Sve OK");
}
}
}
yarn build displays no error, in public folder app.js is updated.
Please help.