如何通过CDN使用Dojo时加载自定义AMD模块? [英] How to load custom AMD modules when using Dojo via CDN?

查看:153
本文介绍了如何通过CDN使用Dojo时加载自定义AMD模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用谷歌的CDN,并尝试使用其加载器加载我自己的AMD模块。我知道我在做错事,但我被卡住了。任何想法?

I am using google's CDN and also trying to load my own AMD modules using their loader. I know I'm doing something wrong but I'm stuck. Any ideas?

    <script src="https://ajax.googleapis.com/ajax/libs/dojo/1.7.0/dojo/dojo.js" 
            type="text/javascript" data-dojo-config="async:true,parseOnLoad:true"></script>
    <script type="text/javascript">
        require(["dojo/_base/kernel", "dojo/_base/loader", "dojo/parser"], function(dojo){
            dojo.registerModulePath("pgGallery", "http://127.0.0.1:8080/js");
        });
        require(["pgGallery/Message"], function(m){
            m.success("foo");
        });
    </script>

http://127.0.0.1:8080/js/Message.js 是模块的位置。

推荐答案

我想到了如何做到这一点: http:/ /dojotoolkit.org/reference-guide/quickstart/cross-domain.html 使用CDN与本地模块。

I figured out how to do it here: http://dojotoolkit.org/reference-guide/quickstart/cross-domain.html under "Using CDN with Local modules".

该页面中的示例:

<script type="text/javascript">
    var dojoConfig = {
        async: true,
        packages: [
            {
                name: "my",
                location: "/absolute/path/to/local/modules"
            }
        ]
    };
</script>

<!-- Bootstrap Dojo From Google's CDN -->
<!-- removing the protocol from src url auto detects if current page is served via http or https and also loads the dojo resources from matching protocol -->
<script
    type="text/javascript"
    src="//ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js">
</script>

<script type="text/javascript">
    require(["my/FooModule"], function(FooModule){
        // ...
    });
</script>

这篇关于如何通过CDN使用Dojo时加载自定义AMD模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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