I am trying to load 2 third party js files in my module,
Followed below steps.
Vendor/Module/view/frontend/layout/default.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="after.body.start">
<block class="Magento\Framework\View\Element\Template"
name="mobile-megamenu.file"
before="-"
template="Vendor_Module::custom.phtml"
/>
</referenceContainer>
</body>
Vendor/Module/view/frontend/templates/custom.phtml
<div id="dl-menu" class="dl-menuwrapper">
<button class="dl-trigger">More</button>
<ul class="dl-menu">
<li>
<a href="#" class="levelTwo">Test</a>
<ul class="dl-submenu">
<li>Test </li>
<li>Test </li>
<li>Test </li>
<li>Test </li>
</ul>
</div>
<script>
require([
"jquery",
"dlmenu",
"modernizr"
], function ($) {
$(document).ready(function(){
$( '#dl-menu' ).dlmenu({
animationClasses : { classin : 'dl-animate-in-2', classout : 'dl-animate-out-2' }
});
$("button.dl-trigger").click(function(){
$("ul.extra-links").toggle();
});
});
});
</script>
Vendor/Module/view/frontend/requirejs-config.js
var config = {
map: {
'*': {
dlmenu: 'Vendor_Module/js/jquery.dlmenu',
modernizr:'Vendor_Module/js/modernizr.custom'
}
}
};
I have Moved both the js files here,
app/code/Vendor/Module/view/frontend/web/js/
I am getting the following errors in console.
require.js:166 Uncaught Error: Script error for: dlmenu.
Uncaught ReferenceError: Cannot read property 'prefixed' of undefined
Can someone help me on this please. Thanks!!
1 Answer 1
I think you have an issue with your requirejs-config.js file, it should be :
var config = {
paths: {
dlmenu: 'Vendor_Module/js/jquery.dlmenu',
modernizr:'Vendor_Module/js/modernizr.custom'
},
shim: {
"dlmenu": ["jquery"],
}
};
You can use deps instead of paths depending on your need. Shim is used to load jquery before dlmenu.
-
Hi @Taschert, thanks for the answer, okay I will check it, have u tried it? I have treis it before but didn't work for meManjunath– Manjunath2020年02月29日 01:36:19 +00:00Commented Feb 29, 2020 at 1:36
-
Thanks @Taschert, its workedManjunath– Manjunath2020年03月02日 06:49:21 +00:00Commented Mar 2, 2020 at 6:49
Explore related questions
See similar questions with these tags.