Override ‘Magento_Checkout/js/view/billing-address.js’ with Custom JS in Magento 2

magento2magento2.2.2requirejs-config.js

I want to override Magento's Magento_Checkout/js/view/billing-address.js with my custom JS file, for that I have added below code in my requirejs-config.js

var config = {
    map: {
        "*": {
            "Magento_Checkout/js/view/billing-address": "Example_Module/js/view/billing-address"
        }
    }
};

This works perfectly and I can see my js file overriding magento's default file.

The issue is when I enable JS minify option from admin panel, my JS file does not get loaded and checkout page displays below error.

Failed to load the Magento_Checkout/js/view/billing-address component.

Is there anyway to resolve this issue?

Best Answer

Solution:

In your modules config.xml file add the following:

Example/Module/etc/config.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <dev>
            <js>
                <minify_exclude>
                    Example_Module/js/view/billing-address.js
                </minify_exclude>
            </js>
        </dev>

    </default>
</config>

rm -rf pub/static/frontend/

php bin/magento setup:static-content:deploy

After doing above steps it is working for me.

Related Topic