javascript RequireJS 插件( order.js )

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10841522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 11:12:48  来源:igfitidea点击:

RequireJS plugin( order.js )

javascriptrequirejs

提问by Joseph Ledesma Gabito

http://requirejs.org/

http://requirejs.org/

I recently downloaded require.js 2.0 and I am getting error in my console:

我最近下载了 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'

Is order.js plugin still supported by requirejs? I don't see its documentation in the website.

requirejs 仍然支持 order.js 插件吗?我在网站上没有看到它的文档。

When I try to remove the file the script breaks.

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

In my index file, I included requirejs script in the head section:

在我的索引文件中,我在 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>

Then in my main.js file:

然后在我的 main.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();
        });
    }
);

I sees to it that App.initialize doesn't have any errors and what App.initialize is doing is just simple geo location. The requirejs simply ask for order.js, and when I put the code it's having the same error as mentioned above.

我确保 App.initialize 没有任何错误,而 App.initialize 所做的只是简单的地理位置。requirejs 只是要求 order.js,当我放置代码时,它具有与上述相同的错误。

Thank you!

谢谢!

回答by Simon Smith

Your assumption that orderis no longer supported is correct. It was removed in favour of the shimconfiguration option:

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

So, the the order plugin has been removed and following the lead of Tim Branyen and Dave Geddes, of use and wrap respectively, requirejs 2.0 integrates that kind of dependency tree specification directly in requirejs.

因此,订单插件已被删除,并在 Tim Branyen 和 Dave Geddes 的带领下,分别使用 use 和 wrap,requirejs 2.0 直接在 requirejs 中集成了这种依赖树规范。

Require 2.0 upgrade notes - https://github.com/jrburke/requirejs/wiki/Upgrading-to-RequireJS-2.0

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

Also, check the shimdocumentation on the RequireJS site - http://requirejs.org/docs/api.html#config-shim

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

回答by Joseph Ledesma Gabito

Oh figured it out.

哦想通了。

//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();
    });
});