1

所以我有一个使用 jspm 的 aurelia 设置。我已经像这样安装了 Bootstrap 4:

jspm install npm:bootstrap@4.0.0-alpha.2

然后在 main.js 我做了:

import 'jquery';
import 'bootstrap';

export function configure(aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging();

  //Uncomment the line below to enable animation.
  //aurelia.use.plugin('aurelia-animator-css');
  //if the css animator is enabled, add swap-order="after" to all router-view elements

  //Anyone wanting to use HTMLImports to load views, will need to install the following plugin.
  //aurelia.use.plugin('aurelia-html-import-template-loader')

  aurelia.start().then(() => aurelia.setRoot());
}

我什至尝试过import $ from 'jquery',但是当我用 BS4 启动 aurelia 骨架时,我得到:

Uncaught Error: Bootstrap's JavaScript requires jQuery

我可以去控制台做 $ 并返回 jquery 的东西。我认为这是一个竞争条件,但不知道如何解决?

编辑:System.config

System.config({
  defaultJSExtensions: true,
  transpiler: "none",
  paths: {
    "*": "dist/*",
    "github:*": "jspm_packages/github/*",
    "npm:*": "jspm_packages/npm/*"
  },
  meta: {
    "bootstrap": {
      "deps": [
        "jquery"
      ]
    }
  },
  map: {
4

3 回答 3

3

利用jspm install bootstrap=github:twbs/bootstrap@4.0.0-alpha.2

bootstrap使用jspmfrom安装时出现问题npm:请参见此处)。

请参阅此文件以了解如何导入它(来自此项目)。

更新:这是应该解决这个问题的拉取请求。

于 2016-06-15T17:22:03.890 回答
2

我最近也遇到了这个问题。尝试安装 jquery 2,而不是 jquery 3。显然,当 jquery 3 作为模块导入时,它不会像在 jquery 2 中那样将其挂起。Bootstrap 4 显然也没有将其作为依赖项请求.

于 2016-06-15T14:10:42.457 回答
0

一种可能的解决方案是从 index.html 的 HEAD 部分中的 CDN 加载 jQuery:

<script   src="https://code.jquery.com/jquery-3.0.0.min.js"   integrity="sha256-JmvOoLtYsmqlsWxa7mDSLMwa6dZ9rrIdtrrVYRnDRH0="   crossorigin="anonymous"></script>

取自https://code.jquery.com。如果需要,请使用不同版本的 jQuery。恕我直言,这实际上是一个更好的部署策略,因为通过从 CDN 加载库,您将在浏览器中获得更多的并发下载(更好的并行性)。

于 2016-06-15T18:33:32.193 回答