requireJS with fileupload plugins

守給你的承諾、 提交于 2019-12-31 06:02:07

问题


In requirejs, we can set the name for js via this:

requirejs.config({
    paths: {
        'jquery': '//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js'
    }
});

And use it with this:

requirejs(['jquery'],function ($) {
    //loaded and can be used here now.
});

But for some plugin like fileuploads required a number of js files. Their document shows how to use it with requirejs: https://github.com/blueimp/jQuery-File-Upload/wiki/How-to-use-jQuery-File-Upload-with-RequireJS

But, how can I manage to put them all into one name?

requirejs(['jquery','fileupload'],function ($) {
    //all fileupload js has been loaded and ready to use
});

So that when I require fileupload, it will load all the required js without requiring them one by one.

Thank you.


回答1:


You could create a meta-module that imports all the necessary resources and bundles them together, the end modules then become transitive dependencies that are loaded implicitly:

fileupload.js

define(['jquery',
        'js/jquery.iframe-transport',
        'js/jquery.fileupload-ui'
], function () {
  // all needed dependencies loaded
});

When you require fileupload you ensure all the needed dependencies are present.



来源:https://stackoverflow.com/questions/23272773/requirejs-with-fileupload-plugins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!