bower或grunt不断从index.html中删除jquery

bower或grunt不断从index.html中删除jquery,jquery,gruntjs,bower,Jquery,Gruntjs,Bower,这让我快发疯了。到目前为止,Bower+Grunt(通过约曼)一直是令人沮丧和浪费时间的主要来源。我只想让我的应用程序使用最新(2.1.0)版本的jquery bowerlist正确地将jquery 2.1.0报告为正式更新 我运行了bower安装——保存jquery以更新到最新版本,它做到了这一点 bowerlist命令现在可以正确地将jquery#2.1.0报告为依赖项,并且 现在,bower.json文件正确地列出了jquery,并将所需版本作为依赖项: { "name": "xxx"

这让我快发疯了。到目前为止,Bower+Grunt(通过约曼)一直是令人沮丧和浪费时间的主要来源。我只想让我的应用程序使用最新(2.1.0)版本的jquery

bowerlist
正确地将jquery 2.1.0报告为正式更新

我运行了
bower安装——保存jquery
以更新到最新版本,它做到了这一点

bowerlist
命令现在可以正确地将
jquery#2.1.0
报告为依赖项,并且 现在,
bower.json
文件正确地列出了jquery,并将所需版本作为依赖项:

{
  "name": "xxx",
  "version": "0.0.0",
  "dependencies": {
    ...
    "angular": "1.2.13",
    "jquery": "~2.1.0",
    "sizzle": "1.10.16",
    "bootstrap": "~3.0.3",
    ...
但是每次我运行
grunt build
grunt service
时,
列表就会从
index.html
中删除,从而阻止整个应用程序正常运行

#> grunt serve
Running "serve" task

Running "clean:server" (clean) task
Cleaning .tmp...OK

Running "bower-install:app" (bower-install) task

jquery was not injected in your file.
Please go take a look in "app/bower_components/jquery" for the file you need, then manually include it in your file.

Running "concurrent:server" (concurrent) task
...

手动添加并不能解决任何问题。我完全卡住了。一定是我做错了什么事,但我已经撞了我的头很长一段时间,而完全没有效率。谢谢。

这里有一个很长的答案,但我只有时间来回答一个很短的问题,我想我最好给出这个答案,而不是什么都没有

bower安装
是一项任务,它取决于bower包在其
bower.json
中正确指定
main
属性。jQueryBower包最近出现了一些东西,它不再指定这个属性。如果没有,
grunt bower安装
也帮不了什么忙

解决方案是在HTML的
块之外手动包含对jQuery的引用


很抱歉让你失望。希望jQuery能很快修复它的bower.json。

这里有一个更好的解决方案,它不会强迫您将脚本标记从其他bower组件中移开。您可以使用
覆盖
部分(在上找到)

将以下部分添加到项目的
bower.json

...
"overrides": {
    "jquery": {
        "main": "dist/jquery.js"
    }
}

几分钟前,我在grunt+yeoman+bower身上看到了同样的问题。在我的例子中,“覆盖”解决方案不起作用

grunt wiredep
继续对app/index.html中的条目重新排序。问题是jquery在bower.json的dependencies部分的位置。在我的例子中,jquery是bower.json中依赖项部分的第9个条目

grunt wiredep 
然后会移动

<script src="bower_components/jquery/dist/jquery.js"></script>
现在,它看起来是这样的(注意jquery如何重新定位到位置#1)


我把这个放在这里是为了让其他人可以使用这个解决方案,如果没有其他办法的话。

简单而合适的解决方案是在bower.json的overrides部分添加这个引用:就像我为jquery ui添加的一样

"overrides": {
    "bootstrap": {
      "main": [
        "less/bootstrap.less",
        "dist/css/bootstrap.css",
        "dist/js/bootstrap.js"
      ]
    },
    "jquery-ui": {
      "main": [
        "themes/base/jquery-ui.css",
        "ui/jquery-ui.js"
      ]
    }
  }

干杯:)

非常感谢您抽出时间!在我的调查中,我确实尝试在JQuery的bower.json中添加缺少的main部分,但没有成功。我目前的“解决方案”(因为我想保留我的工作)是将脚本include移到HTML中的bower控制块之外,正如您正确建议的那样。Stephen,我刚刚意识到您是grunt bower install的作者。再次感谢您的帮助。呃,ACE编辑器有这个问题(ACE构建没有bower.json,并且从index.html中删除…而angular ui ACE很好)。我不喜欢这种变通方法,但我想它现在是最好的:-/使用这种解决方案可能会导致
grunt
构建中出现问题。其他库也会出现这种情况吗?我做了一个bower安装——保存ui路由器,每次我运行grunt serve时,它也会从我的index.html中剥离出来,尽管它在bower.json中看起来是正确的,因为现在我刚刚将引用放在了其他地方,但这种错误行为确实侵蚀了使用bowerIt的实用性,在ngcordova的情况下对我没有帮助-我有bower.json:{。。“重写”:{“bootstrap”:{“main”:[“less/bootstrap.less”,“dist/css/bootstrap.css”,“dist/js/bootstrap.js”]},“ngCordova”:{“main”:[“dist/js/ng cordova.js”]}你使用的是什么版本的grunt?grunt 3.10.5也有同样的情况,但3.10.3似乎没有这个问题。
"dependencies": {
    "jquery": "^2.2.3",
    "angular": "1.4.8",
    "angular-animate": "^1.3.0",
    "angular-aria": "^1.3.0",
    "angular-cookies": "^1.3.0",
    "angular-messages": "^1.3.0",
    "angular-resource": "^1.3.0",
    "angular-route": "^1.3.0",
    "angular-sanitize": "^1.3.0",
}
"overrides": {
    "bootstrap": {
      "main": [
        "less/bootstrap.less",
        "dist/css/bootstrap.css",
        "dist/js/bootstrap.js"
      ]
    },
    "jquery-ui": {
      "main": [
        "themes/base/jquery-ui.css",
        "ui/jquery-ui.js"
      ]
    }
  }