How can I specify library dependencies using SystemJS?

旧巷老猫 提交于 2019-12-22 05:28:16

问题


Using SystemJS, how do I specify that one library depends on another? For example, the Bootstrap JavaScript library depends on jQuery. Based on the SytemJS docs, I assumed I would specify this dependency using System.config.meta property:

System.config({
    baseUrl: './scripts',
    defaultJSExtensions: true,
    map: {
        jquery: './lib/jquery-2.2.0.min.js',
        bootstrap: './lib/bootstrap.min.js'
    },
    meta: {
        bootstrap: {
            deps: ['jquery']
        }
    }
});
System.import('./scripts/app.js');

But this seems to have no effect. When I run my application, the Bootstrap library throws a Bootstrap's JavaScript requires jQuery error - which means Bootstrap is being loaded before jQuery.

How can I ensure that jQuery is always loaded before Bootstrap?


回答1:


After blindly changing things, I happened upon a configuration that seems to work. Here's my config:

System.config({
    defaultJSExtensions: true,
    paths: {
        jquery: './scripts/lib/jquery-2.2.0.min.js',
        bootstrap: './scripts/lib/bootstrap.min.js'
    },
    meta: {
        bootstrap: {
            deps: ['jquery']
        }
    }
});

System.import('./scripts/app.js');

I think the key was changing from map to paths.

EDIT

Side note: after learning a bit more about SystemJS, I'm discovering that it is much easier to let jspm do the hard work of managing my SystemJS configuration.



来源:https://stackoverflow.com/questions/35001692/how-can-i-specify-library-dependencies-using-systemjs

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