You have to set requirejs-config.js like below,
More details, Refer link, How to Resolve RequireJs error in Magento 2
var config = {
paths: {
'flexslider': 'Vendor_Modulejs/jquery.flexslider-min',
'picturefill': 'Vendor_Modulejs/picturefill.min',
'easing': 'Vendor_Modulejs/jquery.easing.1.3',
'hoverintent': 'Vendor_Modulejs/jquery.hoverIntent',
'fitvids': 'Vendor_Modulejs/jquery.fitvids',
'vimeo': 'Vendor_Modulejs/jquery.vimeo.api.min'
},
shim: {
'flexslider': {
deps: ['jquery']
},
'picturefill': {
deps: ['jquery']
},
'easing': {
deps: ['jquery']
},
'hoverintent': {
deps: ['jquery']
},
'fitvids': {
deps: ['jquery']
},
'vimeo': {
deps: ['jquery']
}
}
};
Use above code and remove var folder and try.
Thanks.
You have to set jQuery dependency for your custom script. You have
occurance of problem because of dependency issue.
- For Module/Extension Level
You can set at module/extension level dependency like below,
app/code/Packagename/Modulename/view/frontend/requirejs-config.js
var config = {
paths: {
'slider': "Packagename_Modulename/js/slider"
},
shim: {
'slider': {
deps: ['jquery']
}
}
};
Add slider.js inside path, app/code/Packagename/Modulename/view/frontend/web/js/slider.js
You can use in any template file like this,
<script>
require(["jquery","slider"],function($)(){
$(document).ready(function() {
$(element).slider({
//option
});
});
});
</script>
- Theme Level
If you want to apply require js changes at theme level,
Go to theme module,
app/design/frontend/{Packagename}/{themename}/Packagename_Modulename/requirejs-config.js
Set your theme required js file in requirejs-config.js
var config = {
paths: {
'slider': "Packagename_Modulename/js/slider",
'customjsfile': "Packagename_Modulename/js/customjsfile",
},
shim: {
'slider': {
deps: ['jquery']
},
'customjsfile':{
deps: ['jquery']
}
}
};
Add your js file inside web folder of theme,
app/design/frontend/{Packagename}/{themename}/Packagename_Modulename/web/js/slider.js
app/design/frontend/{Packagename}/{themename}/Packagename_Modulename/web/js/customjsfile.js
In your template file,
<script>
require(["jquery","slider","customjsfile"],function($)(){
$(document).ready(function() {
$(element).slider({
//option
});
});
});
</script>
For your case,
Keep below config in requirejs-config.js file,
var config = {
paths: {
'footerContact': 'Module_Contact/js/contact'
},
shim: {
'footerContact': {
deps: ['jquery']
}
}
};
Inside phtml file,
<script>
require(["jquery","footerContact"],function($)(){
jquery('.element').on('click', function(event) {
console.log('logging');
});
});
</script>
Best Answer
There is no more skin folder but you can still use themes.
As a proof of concept I used you example with
op-checkout-method.js
and this this.Preconditions:
pub/static
folder (remove the pub/static/frontend folder)Actions:
op-checkout-method.js
file from it's module locationapp/code/Magento/Checkout/view/frontend/web/js/opc-checkout-method.js
to the blank theme toapp/design/frontend/Magento/blank/Magento_Checkout/web/js/opc-checkout-method.js
console.log('something')
oralert('something')
in the_create
function of themage.opcCheckoutMethod
widget.Result:
Related Info:
If I run from cli
php dev/tools/Magento/Tools/View/deploy.php
(the script that publishes the static resources) my new js file gets placed inpub/static/frontend/Magento/blank/en_US/Magento_Checkout/js/opc-checkout-method.js
[EDIT]
I found a way to do it via a module.
In
[Namespace]/[Module]/view/frontend/requirejs-config.js
add this:Then create the file
[Namespace]/[Module]/view/frontend/web/js/opc-checkout-method.js
with your content.For testing purposes I cloned the original file and just added again a
console.log
in the_create
function.Also remember to regenerate the public resources for frontend.