loading jquery plugins with require js

前端 未结 2 1395
有刺的猬
有刺的猬 2020-12-23 17:53

I am new to require js, and the problem is I don\'t really understand how to load jQuery plugins.

I would like to load multiple plugins but I already have problems w

2条回答
  •  太阳男子
    2020-12-23 18:21

    Hi I will like to tell you here that if you want to include non AMD scripts (which do not include define() call) , we use shim config . I will like to explain with a simple example of jquery hightlight plugin.

    this will be your config file where you define all paths

    paths:{
        "jquery":"/path/to/jquery",
        "jgHighlight":"/path/to/jquery.highlight"
    },
       shim:{
    
            deps:["jquery"], // jquery.highlight dependeps on jquery so it will load after jquery has been loaded 
            exports:"jqHighlight"
    
       }
    

    Now in a module which starts with define , include jqHighlight like this

    define(["requireModulesArray","jgHighlight"],function(requiredModulesAliasArray){
    
       // no need to include any alias for jgHighlight in function(...)
       //use it like this now
    
         $("#divT").highlight("someText");
    
    });
    

    Similarly other non amd modules will be included and used. Thanks

提交回复
热议问题