I've been trying to load a javascript file conditionally but it doesnt work when i build the app with parcel. I don't know what's happening but it seems like parcel does not build the file when i load it. The function i want to achieve is one that a certain javascript file only loads on Desktop devices/devices with width >= 600px. Tried building with Vs Code Live Serve, and it seemed to work just fine, however when i build with parcel, this function does not work. Any help please?
<script>
var matchMedia = window.matchMedia("(max-width:600px)");
if (matchMedia.matches) {
return;
} else {
var script = document.createElement('script');
script.type = "text/javascript";
script.src = "assets/js/main.js";
document.body.appendChild(script);
}
</script>