Requirejs 使用 shim

编程入门 行业动态 更新时间:2024-10-27 17:16:56
本文介绍了Requirejs 使用 shim的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过requirejs2使用shim,有没有办法告诉requires模块已经加载?

Using shim by requirejs2, there is a way to tell to requires that a module is already loaded?

示例:

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="undescrore.js"></script>
<script type="text/javascript" src="require.js'"></script>
<script type="text/javascript">
    require.config({
        paths: {
            "backbone": '/vendor/js/backbone-min.js'
        },
        shim: {
            'backbone': {
                //These script dependencies should be loaded before loading
                //backbone.js
                deps: ['underscore', 'jquery'], // here I would like to load the already loaded library
            }
        }
    });
</script>

推荐答案

好吧,如果下划线已经加载并且可用,那么您根本不需要垫片.Backbone 将愉快地加载.如果没有,可能是因为下划线没有实际加载.

Well, if underscore is already loaded and available, you do not need the shim at all. Backbone will happily load. If not, it's probably because underscore is not actually loaded.

虽然仅部分使用 require.js 听起来是错误的,但您不妨 AMD 加载它们.为此,您需要像这样更改垫片:

It sounds however wrong to be only partially using require.js, you might as well AMD-load them all. To do that you will need to change your shim like this:

shim: {
    backbone: {
        deps: ["underscore", "jquery"],
        exports: "Backbone"
    },

    underscore: {
        exports: "_"
    }
}

当然还要更新您的路径.

这篇关于Requirejs 使用 shim的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-30 03:43:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/768656.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Requirejs   shim

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!