Requirejs的顺序不适用于优先级配置和CDN依赖项 [英] Requirejs' order does not work with priority config and CDN dependencies

查看:106
本文介绍了Requirejs的顺序不适用于优先级配置和CDN依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下 main.js 代码不遵守优先级顺序(有时未加载 underscore.js backbone.js 需要它时):

The following main.js code do not respect the order of priorities (sometimes underscore.js is not loaded when backbone.js needs it):

require({
    baseUrl:'/scripts',
    priority:[
        "http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js",
        "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js",
        "http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js",
        "http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"
    ]
    },["src/app"], 
    function (app) {
        app.start();
});

在这些CDN依赖项失败之前添加订单!找不到 order.js 错误。

Adding order! before those CDN dependencies fails with a order.js not found error.

推荐答案

我最近更新了RequireJS文档,但我尚未将更改推送到站点:

I recently updated the RequireJS docs, but I have not pushed the change to the site yet:

优先级配置无法加载插件加载的资源。因此,要完成您想做的事情,您可以嵌套require()调用,这将为您提供所需的行为:

The "priority" configuration cannot load resources loaded by plugins. So to accomplish what you are trying to do, you can just nest require() calls, which will give you the behavior you want:

require(
    {
        baseUrl:'/scripts'
    },
    [
        "require",
        "order!http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js",
        "order!http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js",
        "order!http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js",
        "order!http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"

    ], 
    function (require) {
        require(["src/app"], function (app) {
            app.start();
        });
    }
);

这假定您在/scripts/order.js位置中有订单插件。

This assumes you have the order plugin in the /scripts/order.js location.

这篇关于Requirejs的顺序不适用于优先级配置和CDN依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆