requirejs - 如何在Aurelia-CLI中添加系绳以与Bootstrap 4一起使用

标签 requirejs aurelia tether

我正在尝试将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所述,最好将tetherdepsBootstrap中显示出来,以消除重复包含的可能性。基本上,这是更新的代码:
"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 the prepend 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/

相关文章:

javascript - 如何将 RequireJS 用于 Yelp API、客户端 javascript

javascript - SignalR & require.js 配置

aurelia - 动态生成的route-href抛出错误

ios - 如何在越狱的ios设备上启用热点服务

javascript - Browserify shim 似乎没有将 Tether 附加到窗口对象

javascript - 在Requirejs中,我可以用不同的名称注册相同的路径吗?

javascript - socket.io 客户端是否必须存在于全局范围内?

typescript - 如何在 webpack 中使用 underscore.js

javascript - 从组件文件和 View 模型生成原始 HTML 字符串

angular - 如何在 Angular 应用程序中启用 Bootstrap4 工具提示