问题
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