cancel
Showing results for 
Search instead for 
Did you mean: 

Overwrite a js file in a different module with my module?

SOLVED

Overwrite a js file in a different module with my module?

I'm building an extention on the M2 checkout. A requirement for this is that a specific third party module is used for zip code checks. This module works fine except for one bug.

 

Now to fix this bug I need to change one line in the postcode.js file of that module. I would prefer to change that line in my own module to make it easier implementable in different projects.

 

(The problem is that the other module tries to show the region when the region field is unset so it shows undefined so I need to uncomment that line.)

 

Now I know that the file could be overwritten in the theme. I got that answer on the stackexchange, but I would prefer it if there is a solution where i can overwrite it in my module. Is this possible?

 

RStjD

 The file i'm trying to overwrite is in Wezz/Postcodem2 > web > js > view > postcode.js

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Overwrite a js file in a different module with my module?

Hello,

 

you need to create view/frontend/requirejs-config.js 

 

var config = {
   
	config: {
		mixins: {
			'Magento_Swatches/js/swatch-renderer': {
				'ModuleNmae_ConfigurableProductExtended/js/swatch-renderer-mixins': true
			},
		}
	}
};

Same way you can do it


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

View solution in original post

5 REPLIES 5

Re: Overwrite a js file in a different module with my module?

Hello,

 

you need to create view/frontend/requirejs-config.js 

 

var config = {
   
	config: {
		mixins: {
			'Magento_Swatches/js/swatch-renderer': {
				'ModuleNmae_ConfigurableProductExtended/js/swatch-renderer-mixins': true
			},
		}
	}
};

Same way you can do it


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Overwrite a js file in a different module with my module?

Isn't that only useable for overwriting default Magento2 modules? Or also for files in other modules?

Re: Overwrite a js file in a different module with my module?

Hello @SannNL

 

yes, you can override another module as well.

 

Make sure sequence of your module after that module.

 

Hope it will help you if it will work then mark as solution

 

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Overwrite a js file in a different module with my module?

Putting it in the mixin part of requirejs didn't work but putting it in 'map' did. Thanks.

 

var config = {
    config: {
        mixins: {
            'Magento_Checkout/js/view/shipping': {
                'BB_Checkout/js/mixin/shipping-mixin': true
            }
        }
    },
    'map': {
        '*': {
            'Wezz_Postcode/js/view/postcode': 'BB_Checkout/js/view/postcode-overwrite'
        }
    }
};

Re: Overwrite a js file in a different module with my module?

Hello 

 

can you paste the code from requirejs-config.js from pub/static/frontend/PackageName/Themename/en_US?


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer