1

如题。我的文件结构是:

js/ 
 |- bootstrap
 |   |- module1
 |   |- module2
 |
 |- jquery.min.js
 |- main.js

我的 main.js 文件是

requirejs.config({

    paths: {
        dropdowns : 'bootstrap/module1'
        ,fixes : 'bootstrap/module1'
    }
    ,shim: {
        'jquery.min' : ['jquery']
    }
});

requirejs(['jquery', 'dropdowns', 'fixes'], function ( $, Dropdowns, Fixes ) {

    console.log( $ );
    var fixes = new Fixes();

});

现在......它在控制台中引发以下错误:

GET http://myurl/myapp/js/jquery.js 404 (Not Found) 

正如我们所看到的,它用垫片松开了点。我的问题是“如何加载像 'jquery.min.js' 这样的文件 .js 部分之前的点在哪里?”

4

2 回答 2

0

这不是您加载名为 jquery.min 的文件的方式。这行是说 jquery.min 依赖于 jquery,这并没有太大的意义。

    'jquery.min' : ['jquery']

由于 jQuery 定义了一个 AMD 模块,你应该尝试这个来指定路径

requirejs.config({

    paths: {
        dropdowns : 'bootstrap/module1'
        ,fixes : 'bootstrap/module1'
        ,jquery: 'jquery.min'
   }
});

这可能会给出更清晰的解释http://requirejs.org/docs/jquery.html

于 2013-09-05T14:03:49.423 回答
0

如果您只是想说“在请求 'jquery' 模块时,从 'jquery.min.js' 加载它”,那么您的配置应该如下所示:

需要js.config({

paths: {
    dropdowns : 'bootstrap/module1'
    ,fixes : 'bootstrap/module1'
    ,jquery: 'jquery.min'
}

});

如果您需要说您的其他模块需要 jquery ,则 shim 部分将发挥作用:

shim: {
    dropdowns: {
        deps: ['jquery']
    },
    fixes_validate: {
        deps: ['jquery']
    }
}

另请参阅此答案以获取有关以下内容的更多详细信息shimRequirejs 为什么以及何时使用 shim config

于 2013-09-05T14:04:02.577 回答