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

  • Remove the path view/frontend/web – Raj Mohan R Jul 8 at 11:59
  • correct it : 'CustomName' : 'Vendor_Module/js/custom' – Mukesh Prajapati Jul 8 at 12:02
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');
});
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.