如何使用SystemJS指定库依赖项? [英] How can I specify library dependencies using SystemJS?
问题描述
使用 SystemJS ,如何指定一个库依赖另一个库?例如, Bootstrap JavaScript库取决于 SytemJS文档,我假设我将使用System.config.meta
属性指定此依赖项:
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');
但这似乎没有效果.当我运行应用程序时,Bootstrap库会引发Bootstrap's JavaScript requires jQuery
错误-这意味着Bootstrap在jQuery之前被加载.
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.
如何确保始终在Bootstrap之前加载jQuery?
How can I ensure that jQuery is always loaded before Bootstrap?
推荐答案
盲目更改之后,我遇到了一个似乎有效的配置.这是我的配置:
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');
我认为密钥正在从map
更改为paths
.
I think the key was changing from map
to paths
.
编辑
旁注:在学习了有关SystemJS的更多知识之后,我发现 容易得多,而
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.
这篇关于如何使用SystemJS指定库依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!