jquery - 带有 Bootstrap 的 Yeoman : How to choose jQuery version?

标签 jquery twitter-bootstrap internet-explorer-8 yeoman yeoman-generator

我构建了一个自定义 Yeoman 生成器,用于加载 Bootstrap 3 等。

bower.json-模板:

{
  "name": "<%= _.slugify(appname) %>",
  "version": "0.0.0",
  "dependencies": {<% if (includeBootstrap) { %>
    "bootstrap": "~3.0.3",
    "respond": "~1.4.2",
    <% } %>
    <% if (includeD3) { %>
    "d3": "~3.4.4",
    "colorbrewer": "~1.0.0",
    <% } %>
    "modernizr": "~2.6.2"
  }
}

如您所知,Bootstrap 3 包含 jQuery 作为依赖项,这是 Bootstrap 的 bower.json:

{
  "name": "bootstrap",
  "version": "3.0.3",
  "main": [
    "./dist/js/bootstrap.js", 
    "./dist/css/bootstrap.css", 
    "./dist/fonts/glyphicons-halflings-regular.eot",
    "./dist/fonts/glyphicons-halflings-regular.svg",
    "./dist/fonts/glyphicons-halflings-regular.ttf",
    "./dist/fonts/glyphicons-halflings-regular.woff"
  ],
  "ignore": [
    "**/.*",
    "_*",
    "docs-assets",
    "examples",
    "/fonts",
    "js/tests",
    "CNAME",
    "CONTRIBUTING.md",
    "Gruntfile.js",
    "browserstack.json",
    "composer.json",
    "package.json",
    "*.html"
  ],
  "dependencies": {
    "jquery": ">=1.9.0"
  }
}

因此,生成的 yeoman 应用程序包含一个文件夹 bower_components/jquery,其中包含最新的 jQuery 版本(2.1.0 或其他版本) - 不幸的是,它不支持 IE8。

不幸的是,我需要 IE8 支持。

现在,如何告诉我的应用程序应该加载一个包含 bower.json 的 Bootstrap,其中包含 ~1.9.0 而不是 >=1.9.0?

第二个问题:为什么 jQuery 安装在与 Bootstrap 相同的层次结构级别上,即安装在 bower_components/jquery/ 中,而不是安装在 bower_components/bootstrap/bower_components/jquery 中或者其他什么,因为它是 Bootstrap 的唯一依赖项,并且在我的 yeoman bower.json 模板中没有指定?!这是我觉得非常令人困惑的事情。

最佳答案

@puredevotion 的评论是正确的。我做了什么来解决这个问题:我在 Bower.json 中显式添加了 jQuery。 Bootstrap 认识到这一点并且不会加载 jQuery 本身。

这是我更新的 Bower.json:

{
  "name": "<%= _.slugify(appname) %>",
  "version": "0.0.0",
  "dependencies": {<% if (includeBootstrap) { %>
    "bootstrap": "~3.0.3",
    "respond": "~1.4.2",
    <% } %>
    <% if (includeD3) { %>
    "d3": "~3.4.4",
    "colorbrewer": "~1.0.0",
    <% } %>
    "modernizr": "~2.6.2",
    "jquery": "~1.9.0"
  }
}

不过我仍然不知道第二个问题的答案。

关于jquery - 带有 Bootstrap 的 Yeoman : How to choose jQuery version?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22855751/

相关文章:

jquery - 响应式导航 - 如果有 child 则添加一个类(class)

javascript - 纯javascript相当于jquery赋值

javascript - Angular UI Bootstrap Input-Group-Button - 该死的 float 按钮

javascript - jQuery 的 addClass 有效,但浏览器不应用新类

div :hover in IE8 and 9 not working correctly with facebook like box, 上的 CSS 边距变化偶尔跳跃

Javascript 与 IE8 - 预期的标识符、字符串或数字

javascript - 查询 : find closest h2 tag

javascript - JavaScript 上的媒体查询?

jquery - 如何在 jQuery 中切换

javascript - 如何让 AngularJS 应用程序在 IE8 中运行?