admin管理员组文章数量:1313749
I've seen many variations to loading modules which do not support AMD yet, and I would like to know what is the best practice to do so.
Eventually, I would like to write modules like this:
module.js:
define(["jQuery", "Underscore", "Backbone"], function($, _, Backbone) {
... module code here
}
But there are a lot of problems with loading those dependencies using AMD since they are not all AMD pliant.
I've seen many variations to loading modules which do not support AMD yet, and I would like to know what is the best practice to do so.
Eventually, I would like to write modules like this:
module.js:
define(["jQuery", "Underscore", "Backbone"], function($, _, Backbone) {
... module code here
}
But there are a lot of problems with loading those dependencies using AMD since they are not all AMD pliant.
Share Improve this question edited Jan 8, 2012 at 22:34 Charles 51.4k13 gold badges106 silver badges144 bronze badges asked Dec 26, 2011 at 8:57 Ron ReiterRon Reiter 3,9343 gold badges32 silver badges34 bronze badges 3- 1 What do you mean by AMD? Not the CPU family, right? – Thilo Commented Dec 26, 2011 at 9:02
- 1 Nope. Asynchronous module definition. Poor choice of TLA I must admit... :) – Ron Reiter Commented Dec 26, 2011 at 9:02
- 1 A few years back (before the Intel switch, I think), the Mac rumour groups were abuzz with code references to amd. Back then, it was the auto-mount-daemon. ;-) – Thilo Commented Dec 26, 2011 at 9:06
5 Answers
Reset to default 4I've created a todo-list boilerplate web app which loads all modules as AMD modules (without loaders).
Check it out:
https://github./ronreiter/webapp-boilerplate
Thomas Davis has a better example (imo) for loading jquery/underscore/backbone in his non-updated example. Start by looking at the loader here
It uses the RequireJS order plugin found here to load the modules synchronously.
Take a look at this example. It nicely shows how to use backbone along with requirejs. It also shows how you can organize the model, view and collections neatly.
The latest version of RequireJS adds the ability to use NON-AMD JS files.
require.config({
'paths': {
"underscore": "libs/underscore-min",
"backbone": "libs/backbone-min"
},
'shim':
{
backbone: {
'deps': ['jquery', 'underscore'],
'exports': 'Backbone'
}
}
});
Give that a try.
One thing i don't understand about AMD is that looks like it loads necessary js only when it needs but with the demo application it loads all js html css files when you access the app for the first page load.
本文标签:
版权声明:本文标题:javascript - What is the best way to include jQuery, Underscore, and Backbone as AMD modules using require.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741957837a2407092.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论