我正在尝试将Bootstrap 4添加到Aurelia
中。我只能使CSS
正常工作,但bootstrap.js
需要Tether
,但由于在控制台中不断出现此错误,我无法将其包括在内:
Bootstrap tooltips require Tether
我尝试了一些
"jquery",
"Tether",
{
"name": "tether",
"path": "../node_modules/tether/dist",
"main": "js/tether.min",
"exports": "Tether",
"resources": [
"css/tether.css"
]
},
{
"name": "bootstrap",
"path": "../node_modules/bootstrap/dist",
"main": "js/bootstrap.min",
"deps": ["tether", "jquery"],
"exports": "$",
"resources": [
"css/bootstrap.css"
]
},
它确实捆绑了,但它仍在提示缺少
Tether
。我在另一个stack answer上阅读,我必须用这个来制作ethert
available globally which could be done via
requirejs.config.js`define(['lib/tether.min'], function(tether) {
window.Tether = tether;
});
但是
Aurelia
没有这样的配置。
最佳答案
在花了更多时间之后,我相信我想到了一些可行的方法。我再也看不到错误,并且现在可以使用Bootstrap tooltip
,因此我将假定这是有效的解决方案。
所有更改都在aurelia.json
配置文件中进行,如下所示:
"prepend": [
"node_modules/bluebird/js/browser/bluebird.core.js",
"node_modules/tether/dist/js/tether.min.js",
"scripts/require.js"
],
"dependencies": [
...
"aurelia-templating-binding",
"jquery",
"tether",
{
"name": "bootstrap",
"path": "../node_modules/bootstrap/dist",
"main": "js/bootstrap.min",
"deps": ["jquery", "tether"],
"exports": "$",
"resources": [
"css/bootstrap.css"
]
},
...
因此,基本上,我只需要将其添加到
prepend
即可使其正常运行。还要注意,在tether
数组中添加deps[]
无效(可能是因为Tether
现在与prepend
一起是全局的),但是我想在那儿看到它仍然是一个依赖项。编辑
如@ Paul-Sebastian所述,最好将
tether
从deps
的Bootstrap
中显示出来,以消除重复包含的可能性。基本上,这是更新的代码:"tether",
{
"name": "bootstrap",
"path": "../node_modules/bootstrap/dist",
"main": "js/bootstrap.min",
"deps": ["jquery"],
"exports": "$",
"resources": [
"css/bootstrap.css"
]
},
编辑#2
现在还有一个
append
部分,该部分刚刚添加到Aurelia-CLI
中,以帮助使用带有插件的旧版库。该部分内容如下:A Very Stubborn Legacy Library With Plugins
Some legacy libraries may support plugins which you also want included in your bundle. In some cases these plugins depend on a global object defined by the main library, so it is important that the plugins exist later in the bundle than the main library scripts. These plugins can go in the
append
section, which works exactly the same as theprepend
section but the scripts are appended to the end of the bundle, after all other items. Like the prepend section all items are relative to the project folder, not the src.
关于requirejs - 如何在Aurelia-CLI中添加系绳以与Bootstrap 4一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39432962/