RequireJS如何从果酱文件包部分指定垫片依赖项 [英] RequireJS how specify shim dependency from jam file package section
问题描述
我正在一个带有骨干模板的项目中,该模板使用RequireJS来加载模块,并使用JamJS来管理它们.
我的要求config.js
文件如下:
I'm working in a project with backbone-boilerplate which uses RequireJS to load modules and JamJS to manage them.
My require config.js
file is as follows:
require.config({
deps: ["../vendor/jam/require.config", "main"],
paths: {
"backbone.localStorage": "../vendor/backbone.localStorage-1.0/backbone.localStorage"
},
shim: {
"backbone.localStorage": {
deps: ['backbone']
}
}
});
如您所见,果酱配置文件jam/require.config.js
中的RequireJS加载配置指定了主干,jquery和下划线.接下来是文件的一部分:
As you can see the RequireJS load config from jam config file jam/require.config.js
which specifies backbone, jquery and underscore. Next is a piece of the file:
"packages": [
{
"name": "backbone.layoutmanager",
"location": "../vendor/jam/backbone.layoutmanager",
"main": "backbone.layoutmanager.js"
}
{
"name": "backbone",
"location": "../vendor/jam/backbone",
"main": "backbone.js"
}
],
"version": "0.2.11",
"shim": {
"backbone.layoutmanager": {
"deps": [
"jquery",
"backbone",
"lodash"
],
"exports": "Backbone.LayoutManager"
}
"backbone": {
"deps": [
"jquery",
"lodash"
],
"exports": "Backbone"
}
}
};
我要在我的config.js
中指定主干.localStorare库取决于在包部分中定义的主干.
另外,如果我按以下方式指定主干路径,则它找到了主干库,但发现一条错误消息,提示未加载下划线:
What I want is to specify in my config.js
the backbone.localStorare library depends on backbone defined in the package section.
Also if I specify the backbone path as follows, then it found backbone library but an error message is found saying underscore is not loaded:
require.config({
deps: ["../vendor/jam/require.config", "main"],
paths: {
"backbone": "../vendor/jam/backbone/backbone",
"backbone.localStorage": "../vendor/backbone.localStorage-1.0/backbone.localStorage"
},
shim: {
"backbone.localStorage": {
deps: ['backbone']
}
}
});
我可以使用jamjs添加bone.localStorage库,但是可用软件包的版本较旧,因此我希望手动下载最后一个并手动添加.
I could add backbone.localStorage library using jamjs but the version of the available package is old so I prefer to download the last one manually and include by hand.
任何想法或帮助将不胜感激.
Any ideas or help will be appreciated.
推荐答案
主干需要下划线& jQuery :
shim: {
"backbone": {
"deps": [ "underscore", "jquery" ],
"exports": "Backbone" //attaches "Backbone" to the window object
},
"underscore": {
"exports": "_"
}
}
所以我认为最好改编jam/require.config.js
.
接下来,是您问题中的packages
部分,这是jam/require.config.js
的一部分吗?位置相对于jam/require.config.js
的位置吗?
Next, the packages
section in your question, that's a part of jam/require.config.js
? Is location relative to the location of jam/require.config.js
?
您是否尝试过在自己的config.js中添加packages
部分:
Have you tried to add a packages
section in your own config.js:
"packages": ["backbone", "backbone.layoutmanager"]
这篇关于RequireJS如何从果酱文件包部分指定垫片依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!