1

app/code/{vendor}/{module}/view/frontend/requirejs-config.js

var config = {
 map: {
 '*': {
 'Magento_Swatches/js/swatch-renderer' : 'Wac_SwatchName/js/swatch-renderer',
 'magento-swatch.renderer' : 'Magento_Swatches/js/swatch-renderer',
 'CustomName' : 'Vendor_Module/view/frontend/web/js/custom',
 }
 }
};

app/code/Vendor/Module/view/frontend/web/js/custom.js

$(document).on('swatch.initialized', function() {
 alert('test');
}

Only My Custom Js file Works When my Custom module load, But now Custom js not loading Properly ,Please Check my custom js file and requirejs-config file

asked Jul 8, 2019 at 11:55
2
  • Remove the path view/frontend/web Commented Jul 8, 2019 at 11:59
  • correct it : 'CustomName' : 'Vendor_Module/js/custom' Commented Jul 8, 2019 at 12:02

1 Answer 1

1

Call correct module name and file name in requirejs-config.js

 "CustomName": "Vendor_Module/js/custom"

Need to declare require method in custom.js

require([
 "jquery"
], function($) {
$(document).on('swatch.initialized', function() {
alert('test');
});
});
answered Jul 8, 2019 at 11:57
3
  • Is it working fine? Commented Jul 8, 2019 at 12:05
  • clear generated folder Commented Jul 8, 2019 at 12:07
  • rm -rf var/cache/ var/view_preprocessed/ generated/ Commented Jul 8, 2019 at 12:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.