How to rewrite /lib/web/magnifier/magnifier.js file in a custom module in magento 2.3?
-
08-04-2021 - |
Question
Can we rewrite files in the lib
folder?
If we can, I want to know how to rewrite /lib/web/magnifier/magnifier.js
file in a custom module.
Solution
Try it below in the custom module. This is a working example.
- Create
requirejs-config.js
inapp/code/Custom/Pro/view/frontend directory
if not exists.
var config = {
map: {
'*': {
"magnifier/magnifier": "Custom_Pro/js/magnifier/magnifier"
}
},
shim:{
"Custom_Pro/magnifier/magnifier":["jquery"]
}
};
Create file named
magnifier.js
inapp/code/Custom/Pro/view/frontend/web/js/magnifier
directory. Copy originalmagnifier.js
file fromlib/web/magnifier/magnifier.js
and paste it inapp/code/Custom/Pro/view/frontend/web/js/magnifier
directory.Make the required changes in the
magnifier.js
located in theapp/code/Custom/Pro/view/frontend/web/js/magnifier/magnifier.js
Execute below command in order to effect at frontend
php bin/magento setup:upgrade
php bin/magento s:s:d -f -s standard
Note:
1. Change your custom module from Custom/Pro
.
2. To confirm check below file calling on the frontend.
www.example.com/static/versionXXXXXX/frontend/Vendor/Theme/en_US/requirejs-config.js
For More Info. Refer Replace a default JS component section available at the below URL. https://devdocs.magento.com/guides/v2.3/javascript-dev-guide/javascript/custom_js.html
OTHER TIPS
You can overwrite in design folder,
app/design/frontend/Vendor/Theme/web/magnifier/magnifier.js