Home  >  Article  >  Web Front-end  >  Add custom JS under Magento2 module

Add custom JS under Magento2 module

不言
不言Original
2018-03-30 17:34:442118browse

This article will share with you about adding custom JS under the Magento2 module. The steps are also relatively clear. Friends in need can refer to it

Let’s take a look at what to do first

1. Self-written or third-party JS files

Add your own files in the following location:

//view//web/js/

Example: //view/< area>/web/js/my.js

2. Configuration file

Add requirejs-config.js file for configuration reference
Add to

//view//

Example: //view//requirejs-config.js

var config = {
    map: {
        '*': {
            myjs: 'VendorName_ModuleName/js/my'
        }
    }
};

Here myjs calls the subsequent requirejs

3 .Modify the phtml template

and then you can call it like this

require(['jquery','myjs'],function($){
    //myjs functions
}

4. Directory structure

Borrow other people’s pictures

Add custom JS under Magento2 module


Related recommendations:

What kind of configuration is required for a magento2 website with 100,000 SKUs?

Magento20 How to set the path prompt information of the front page?

magento2 Add payment method payment method

The above is the detailed content of Add custom JS under Magento2 module. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn