哪些脚本加载器(AMD 或非 AMD)可与 Backbone.js/Underscore 一起使用?

发布于 2024-12-26 20:23:13 字数 448 浏览 0 评论 0原文

一周以来,我开始学习如何将 require.js 与 Backbone.jsUnderscore.js 一起使用。

这是一个非常困难的事情,但 3 天前我读到 Underscore 将不再支持 Require.js(AMD)!现在我有点困惑。

我真的很喜欢脚本加载器的概念,不想错过它!

有人已经成功使用带有 Backbone.js(0.5.3) 和 Underscore(1.3.0) 的脚本加载器吗?

谢谢您的帮助!

链接:另一个解决方案此处

For a week i started learning how to use require.js with Backbone.js and Underscore.js.

It's a really difficult stuff, but 3 days ago i read that Underscore will not supporting Require.js(AMD) anymore! Now i'm a bit confuse.

I really like the Concept of Script Loader and dont want to miss it!

Have someone already successfully used a Script Loader with Backbone.js(0.5.3) and Underscore(1.3.0)?

Thank you for helping!

Link : another solution here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

静谧 2025-01-02 20:23:13

我目前在 Backbone Boilerplate 中使用 underscore 1.3 和 Backbone 0.5.3。你可以看到我在那里做什么:

https://github.com/tbranyen/backbone-boilerplate

I am currently using underscore 1.3 and Backbone 0.5.3 in my Backbone Boilerplate. You can see what I'm doing there:

https://github.com/tbranyen/backbone-boilerplate

新雨望断虹 2025-01-02 20:23:13

即使它本身不支持 AMD 模块样式,您仍然可以使下划线与 require.js 一起使用。

您仍然可以通过代理模块将其作为正常的外部 javascript 源加载。

它的要点是这段代码:

// Filename: libs/underscore/underscore
// Loads the original underscore file from the libs/underscore folder
define(['order!libs/underscore/underscore-min'], function(){
  // Tell Require.js that this module returns a reference to Underscore
  return _;
});

完整的教程可以在这里找到: http:// backbonetutorials.com/organizing-backbone-using-modules/

you can still make underscore work with require.js even though it does not natively supports AMD module style.

you can still load it as a normal external javascript source, through a proxy module.

the gist of it is this piece of code:

// Filename: libs/underscore/underscore
// Loads the original underscore file from the libs/underscore folder
define(['order!libs/underscore/underscore-min'], function(){
  // Tell Require.js that this module returns a reference to Underscore
  return _;
});

the full tutorial can be found here: http://backbonetutorials.com/organizing-backbone-using-modules/

久而酒知 2025-01-02 20:23:13

在我看来,Require.js 是最好的替代方案,因为它包含一个优化器(缩小和串联),并允许您解耦您的 Backbone 代码到模块中。

如果您对如何将 Require.js 与最新版本的 Backbone.js 和 Underscore.js 集成感到困惑,请查看我在 github 上创建的样板代码。请记住,我使用 John-David Dalton 的 lodash 而不是 下划线,因为 lodash 提供了更好的性能和自定义构建过程。我还使用 Require.js 2.0 提供的 Shim 配置来制作非 AMD 兼容脚本,例如 Backbone、AMD/Require.js 兼容。

https://github.com/gfranko/Backbone-Require-Boilerplate

Require.js is the best alternative in my opinion, since it includes an optimizer (minification and concatenation) and allows you to decouple your Backbone code into modules.

If you are confused on how to integrate Require.js with the latest versions of Backbone.js and Underscore.js, check out the boilerplate code I created on github. Keep in mind that I am using lodash by John-David Dalton instead of underscore because lodash provides better performance and a custom build process. I am also using the Shim configuration that Require.js 2.0 provided to make non-AMD compatible scripts, like Backbone, AMD/Require.js compatible.

https://github.com/gfranko/Backbone-Require-Boilerplate

苏璃陌 2025-01-02 20:23:13

我这里也有一些...

https://github.com/jcreamer898/RequireJS-Backbone -入门
https://github.com/jcreamer898/Savefavs

更新 2012 年 7 月 7 日

版本的 RequireJS 允许使用以下代码的非 AMD 兼容库。

require.config({ 
    'paths': { 
    "underscore": "libs/underscore-min", 
        "backbone": "libs/backbone-min"
    },
    'shim': 
    {
        backbone: {
            'deps': ['jquery', 'underscore'],
            'exports': 'Backbone'
        }
    }   
});

I have a few here as well...

https://github.com/jcreamer898/RequireJS-Backbone-Starter
https://github.com/jcreamer898/Savefavs

UPDATE July 7/08/2012

The latest version of RequireJS allows NON-AMD compliant libraries with the following code.

require.config({ 
    'paths': { 
    "underscore": "libs/underscore-min", 
        "backbone": "libs/backbone-min"
    },
    'shim': 
    {
        backbone: {
            'deps': ['jquery', 'underscore'],
            'exports': 'Backbone'
        }
    }   
});
獨角戲 2025-01-02 20:23:13

你试过labjs还是headjs吗?

http://labjs.com/

http://headjs.com

啊,还有耶普诺普!

http://yepnopejs.com/

Do you tried labjs or headjs?

http://labjs.com/

http://headjs.com

Ah, theres the yepnope too!

http://yepnopejs.com/

窝囊感情。 2025-01-02 20:23:13

我找到了一个真正适合我的解决方案:Tim Brayen

define([
'jquery',
'use!underscore',
'use!backbone',

我用它来添加jquery插件,自定义js,下划线和主干(不改变代码!)...但是jquery mobile似乎有问题...

你也可以看看wrap,我还没有测试过!

I found a Solution which really work for me : Tim Brayen

define([
'jquery',
'use!underscore',
'use!backbone',

I use it to add jquery plugin, custom js , underscore and backbone( without changing the code!)... but it seems to have a problem with jquery mobile...

you can also take a look to wrap, i have not tested it yet!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文