Getting dependencies to load correctly in requirejs (autobahn and whenjs)

柔情痞子 提交于 2019-12-08 05:06:15

问题


I have been stuck on this problem for the past few hours. I'm trying to get autobahnjs and whenjs to be loaded correctly by requirejs.

require.config({
    paths: {
        angular:            '../bower_components/angular/angular',
        angularBootstrap:   '../bower_components/angular-bootstrap/ui-bootstrap',
        bootstrap:          '../bower_components/bootstrap/dist/js/bootstrap',
        jquery:             '../bower_components/jquery/jquery',
        chosen:             '../bower_components/chosen/chosen.jquery.min',
        text:               '../bower_components/requirejs-text/text',
        autobahn:           '../bower_components/autobahnjs/autobahn/autobahn'

    },
    packages: [
       { name: 'when', location: '../bower_components/when/', main: 'when' }
    ],
    baseUrl: '/bundles/example/app/scripts/',
    shim: {
        angular : { 
            exports : 'angular'
        },
        angularBootstrap: {
            deps: ['angular']
        },
        autobahn: {
            deps: ['when']
        }
    },
    priority: [
        'angular'
    ]
});

require
( [
    'angular',
    'app',
    'autobahn',
    'angularBootstrap',
    'jquery',
    'bootstrap',
    'chosen',
    'controllers/event',
    'services/notify'
], function(angular, app) {
    // more code here
});

Autobahnjs has a dependency on whenjs. All the files are loaded (and in the correct order). but when is always undefined. I have absolutely no idea what I'm doing wrong. I've tried all sorts of ways to solve it. I also have a bower.json file if this helps anyone replicate the problem. Thanks in advance.

EDIT: Autobahnjs does not currently support AMD. Whenjs, however, does support it.


回答1:


As you have noticed already, there is an issue for adding requirejs support to AutobahnJS. There is also more embedded stuff inside AutobahnJS bundled for "convenience", mainly parts from cryptojs.

The challenge simply is: how to best serve all users, not matter if and what module loader they use, and if they want convenience (bundled stuff) or prefer to have stuff separate (and manage/load that themselves).

I can't promise, but I try to address it with priority. However, for further discussion, I think the best place would be the GitHub issue.




回答2:


This has now been implemented in v0.8.0



来源:https://stackoverflow.com/questions/19408177/getting-dependencies-to-load-correctly-in-requirejs-autobahn-and-whenjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!