1

I have a custom module that uses a js file defined in:

Vendor/Module/view/frontend/web/js/sub/directory/myfile.js.

Works fine. I want to use a different file within a theme; from the documentation it looks like I should drop the new js file in

app/design/frontend/vendor/theme/Vendor_Module/web/js/sub/directory/myfile.js

but it does not seem to be working. After running setup:static-content:deploy the pub/static/etc directory contains the same myfile.js that is in the Vendor/Module rather than in the theme. (pub/static/frontend/vendor/theme/en_US/Vendor_Module/js/sub/directory/myfile.js)

How do I override a modules javascript file (contained in a sub directory) in a theme?

1 Answer 1

3

You have to use requirejs-config.js to override js files of module :

Step-1: To do this, place requirejs-config.js file in your theme root folder ( same path where your registration.php, theme.xml is placed ) and content will be like :

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

var config = {
    "map": {
        "*": {
            "jsmodule-identifier": "js/file-override"
        }
    }
};

Step-2: copy js file from module folder and place that file in your theme/web/js/file-overrid.js folder

NOTE : to verify file mapping identifier, view source of your site html page and check requireis-config.js file

Your Answer

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

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