Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有没有计划添加类似 requirejs 的 shim 机制 #22

Open
GilbertSun opened this issue Nov 6, 2015 · 2 comments
Open

有没有计划添加类似 requirejs 的 shim 机制 #22

GilbertSun opened this issue Nov 6, 2015 · 2 comments

Comments

@GilbertSun
Copy link

requirejs 有 shim 的机制,能够使用一个非模块化的文件

requirejs.config({
    //Remember: only use shim config for non-AMD scripts,
    //scripts that do not already call define(). The shim
    //config will not work correctly if used on AMD scripts,
    //in particular, the exports and init config will not
    //be triggered, and the deps config will be confusing
    //for those cases.
    shim: {
        'backbone': {
            //These script dependencies should be loaded before loading
            //backbone.js
            deps: ['underscore', 'jquery'],
            //Once loaded, use the global 'Backbone' as the
            //module value.
            exports: 'Backbone'
        },
        'underscore': {
            exports: '_'
        },
        'foo': {
            deps: ['bar'],
            exports: 'Foo',
            init: function (bar) {
                //Using a function allows you to call noConflict for
                //libraries that support it, and do other cleanup.
                //However, plugins for those libraries may still want
                //a global. "this" for the function will be the global
                //object. The dependencies will be passed in as
                //function arguments. If this function returns a value,
                //then that value is used as the module export value
                //instead of the object found via the 'exports' string.
                //Note: jQuery registers as an AMD module via define(),
                //so this will not work for jQuery. See notes section
                //below for an approach for jQuery.
                return this.Foo.noConflict();
            }
        }
    }
});

mod 有计划添加这个支持吗?

@oxUnd
Copy link
Contributor

oxUnd commented Nov 6, 2015

没有,不打算花时间在这类事情上,明没有什么卵用。

@GilbertSun
Copy link
Author

恩,我想问一下,之所以觉得没有价值是因为大部分流行的库都会提供 commonjs 的暴露接口吗?还是因为其他的考虑

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants