0

我正在尝试从 CDN 模块定义嵌套依赖项。

我收到以下错误:配置

行:1765 错误:./modules/MyConcreteWidget/templates.htm HTTP 状态:404

似乎 CDN "text!./pathing"认为它位于 LOCAL Web 应用程序中。引用的所有文件确实存在于 CDN 中,并且可以通过浏览器地址栏调出。

我是否必须将对“MyWidget”的调用包装在要求(本身)中?

本地需要配置看起来像:

require.config({
    paths:
    {
        , jquery: '/scripts/jQuery/jquery-1.8.3.min'
        , jsRender: '/scripts/jQuery/jsrender-1.0pre'
        , text: '/scripts/RequireJS/2.1.4/text-2.0.5'
        , domReady: '/scripts/RequireJS/2.1.4/domReady-2.0.1'
        , 'myConcreteWidget': '/Modules/MyConcreteWidget/control' 
        , 'myWidet': 'http://server1/Modules/MyWidget/control'
    },
shim:
    {
        'jsRender': { deps: ['jquery'] }
    }
});

本地需求看起来像:

require(['myConcreteWidget', 'domReady'],

    function (myConcreteWidget, domReady) {

        domReady(function () {

                // Use the concrete widget here...
        });
    });

本地定义看起来像:myConcreteWidget
此定义将使用 CDN“小部件”作为依赖项。

define(
    [
        'myWidget'
    ],
    function (myWidget) {

        var concrete = new myWidget.MyWidget();

        // Configure the concrete here...

        // Return concrete widget here
        return concrete;
    });

CDN 定义看起来像:myWidget

define(
    [
      'jquery'
    , 'jsRender'
    , 'text!./templates.htm'
    ],
    function ($, jsRender, templates) {

        $('body').append(templates);

        function MyWidget(){
            this.widgetId = 0;
            this.name = 'Something Awesome';
        };

        return { MyWidget: MyWidget};
    });

更新:
模板文件只不过是 SCRIPT 标签(用于模板)。

4

1 回答 1

1

相对模块 ID 是相对于参考 ID 而不是路径解析的。所以在这种情况下,由于'myWidget'要求'./templates',它被解析为位于模块ID命名空间顶部的'templates',因此在baseUrl下查找,除非有其他配置,比如路径配置在玩。因此,您可能可以为“模板”输入路径条目以获得所需的分辨率。

另请注意,文本插件存在跨域限制:https ://github.com/requirejs/text

于 2013-03-01T21:53:43.260 回答