Skip to main content

Requirejs-config file: app/code/Vendor/Module/view/frontend/requirejs-config.js

var config = {
    paths: {            
         'myfile': "Vendor_Modulename/js/myfile"
      },   
    shim: {
    'myfile': {
        deps: ['jquery']
    }
  }
} 

Your js file should be in: app/code/Vendor/Module/view/frontend/web/js/myfile.js

Now you can use anywhere in your template file by calling the below method:

<srcipt><script>
 require(["jquery","myfile"],function($,myfile){
     $(document).ready(function(){
        //call your js here...
     })
 })
</script>

Requirejs-config file: app/code/Vendor/Module/view/frontend/requirejs-config.js

var config = {
    paths: {            
         'myfile': "Vendor_Modulename/js/myfile"
      },   
    shim: {
    'myfile': {
        deps: ['jquery']
    }
  }
} 

Your js file should be in: app/code/Vendor/Module/view/frontend/web/js/myfile.js

Now you can use anywhere in your template file by below method:

<srcipt>
 require(["jquery","myfile"],function($,myfile){
     $(document).ready(function(){
        //call your js here...
     })
 })
</script>

Requirejs-config file: app/code/Vendor/Module/view/frontend/requirejs-config.js

var config = {
    paths: {            
         'myfile': "Vendor_Modulename/js/myfile"
      },   
    shim: {
    'myfile': {
        deps: ['jquery']
    }
  }
} 

Your js file should be in: app/code/Vendor/Module/view/frontend/web/js/myfile.js

Now you can use anywhere in your template file by calling the below method:

<script>
 require(["jquery","myfile"],function($,myfile){
     $(document).ready(function(){
        //call your js here...
     })
 })
</script>

Filepath is,Requirejs-config file: Vendor_Modulenameapp/webcode/jsVendor/myfileModule/view/frontend/requirejs-config.js

requirejs-config.js
var config = {
    paths: {            
         'myfile': "Vendor_Modulename/js/myfile"
      },   
    shim: {
    'myfile': {
        deps: ['jquery']
    }
  }
} 

Your js file should be in: using,You can use anywhere in your template file by below method,app/code/Vendor/Module/view/frontend/web/js/myfile.js

Now you can use anywhere in your template file by below method:

<srcipt>
 require(["jquery","myfile"],function($,myfile){
     $(document).ready(function(){
        //call your js here...
     })
 })
</script>

Filepath is, Vendor_Modulename/web/js/myfile.js

requirejs-config.js
var config = {
    paths: {            
         'myfile': "Vendor_Modulename/js/myfile"
      },   
    shim: {
    'myfile': {
        deps: ['jquery']
    }
  }
} 

using,You can use anywhere in your template file by below method,

<srcipt>
 require(["jquery","myfile"],function($,myfile){
     $(document).ready(function(){
        //call your js here...
     })
 })
</script>

Requirejs-config file: app/code/Vendor/Module/view/frontend/requirejs-config.js

var config = {
    paths: {            
         'myfile': "Vendor_Modulename/js/myfile"
      },   
    shim: {
    'myfile': {
        deps: ['jquery']
    }
  }
} 

Your js file should be in: app/code/Vendor/Module/view/frontend/web/js/myfile.js

Now you can use anywhere in your template file by below method:

<srcipt>
 require(["jquery","myfile"],function($,myfile){
     $(document).ready(function(){
        //call your js here...
     })
 })
</script>
added 8 characters in body
Source Link
Ronak Chauhan
  • 6.2k
  • 2
  • 30
  • 66

Filepath is, Vendor_Modulename/web/js/myfile.js

requirejs-config.js
var config = {
    paths: {            
         'myfile': "Vendor_Modulename/js/myfile"
      },   
    shim: {
    'myfile': {
        deps: ['jquery']
    }
  }
} 

using,You can use anywhere in your template file by below method,

<srcipt>
 require(["jquery","myfile"],function($,myfile){
     $(document).ready(function(){
        //call your js here...
     })
 })
</script>

Filepath is, Vendor_Modulename/web/js/myfile.js

requirejs-config.js
var config = {
    paths: {            
         'myfile': "Vendor_Modulename/js/myfile"
      },   
    shim: {
    'myfile': {
        deps: ['jquery']
    }
}

using,You can use anywhere in your template file by below method,

<srcipt>
 require(["jquery","myfile"],function($,myfile){
     $(document).ready(function(){
        //call your js here...
     })
 })
</script>

Filepath is, Vendor_Modulename/web/js/myfile.js

requirejs-config.js
var config = {
    paths: {            
         'myfile': "Vendor_Modulename/js/myfile"
      },   
    shim: {
    'myfile': {
        deps: ['jquery']
    }
  }
} 

using,You can use anywhere in your template file by below method,

<srcipt>
 require(["jquery","myfile"],function($,myfile){
     $(document).ready(function(){
        //call your js here...
     })
 })
</script>
added 265 characters in body
Source Link
Rakesh Jesadiya
  • 42.4k
  • 19
  • 132
  • 184
Loading
Source Link
Rakesh Jesadiya
  • 42.4k
  • 19
  • 132
  • 184
Loading