RequireJS plugin( order.js )

RequireJS plugin( order.js )

本文关键字:js order plugin RequireJS      更新时间:2023-09-26

http://requirejs.org/

我最近下载了require.js 2.0,但控制台中出现错误:

Uncaught TypeError: Object function (){var g=ga.call(arguments,0),e;if(f&&v(e=g[g.length-1]))e.__requireJsBuild=!0;g.push(d);return b.apply(null,g)} has no method 'nameToUrl'

requirejs 是否仍然支持 order.js 插件?我在网站上看不到其文档。

当我尝试删除文件时,脚本中断。

在我的索引文件中,我在 head 部分包含了 requirejs 脚本:

<!DOCTYPE html>
<html>
    <head>
        <title>
            My Mobile Application
        </title>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
        <link rel="stylesheet" href="public/css/style.css" />
        <script data-main="scripts/main.js" src="scripts/require.js"></script>
    </head>
    <body></body>
</html>

然后在我的主.js文件中:

requirejs.config({
    //By default load any module IDs from js/lib
    baseUrl: 'js/lib',
    //except, if the module ID starts with "app",
    //load it from the js/app directory. paths
    //config is relative to the baseUrl, and
    //never includes a ".js" extension since
    //the paths config could be for a directory.
    paths: {
        app: '../app',
        assets: '../assets',
        views: '../app/views',
        templates: '../app/templates',
        collections: '../app/collections',
        models: '../app/models'
    }
});
// Start the main app logic.
requirejs([
    'jquery/jquery',
    'assets/jqm.config',
    'jquery/mobile',
    'text'
]);
require([
    'app'
    ],
    function( App ){
        $(document).ready( function(){
            App.initialize();
        });
    }
);
我确保App.initialize没有任何

错误,App.initialize所做的只是简单的地理位置。requirejs 只是要求 order.js,当我输入代码时,它会出现与上面提到的相同的错误。

谢谢!

您不再支持order的假设是正确的。它被删除以支持shim配置选项:

因此,订单插件已被删除并遵循以下领导 Tim Branyen 和 Dave Geddes,分别使用和包装,需要 2.0 将这种依赖树规范直接集成到 requireJS 中。

需要 2.0 升级说明 - https://github.com/jrburke/requirejs/wiki/Upgrading-to-RequireJS-2.0

另外,请查看 RequireJS 站点上的shim文档 - http://requirejs.org/docs/api.html#config-shim

哦,

想通了。

//This is our main applicatoon boot loader or bootstrap
//here we are loading necessary scripts dependencies like
//jquery, jqm.config, mobile, text

requirejs.config({
    baseUrl: 'js/libs',
    //except, if the module ID starts with "app",
    //load it from the js/app directory. paths
    //config is relative to the baseUrl, and
    //never includes a ".js" extension since
    //the paths config could be for a directory.
    paths: {
        app: '../app',
        assets: '../assets',
        views: '../app/views',
        templates: '../app/templates',
        collections: '../app/collections',
        models: '../app/models'
    }
});
// Start the main app logic.
require(["jquery","assets/jqm.config","jquery/mobile","text","app"], 
    function(
    $,
    config,
    mobile,
    text,
    App
    ) {
    //the jquery.alpha.js and jquery.beta.js plugins have been loaded.
    $(function() {
        App.initialize();
    });
});