Gruntjs Grunt正在删除index.html内容

Gruntjs Grunt正在删除index.html内容,gruntjs,yeoman,Gruntjs,Yeoman,我注意到,在与Yeoman合作的几个项目中,当我运行任何grunt build,grunt service命令时,内容(脚本标记、链接标记等)都会从我的index.html文件中删除。你知道为什么会这样吗?以及如何修复它。特别是从我的bower_components文件夹中导入的内容似乎正在发生,但我也有过删除字体awesome cdn的实例 如果有区别的话,我正在使用Yeoman为AngularJS开发。可能有点明显,但是您正在编辑应用程序目录中的index.html,而不是dist/inde

我注意到,在与Yeoman合作的几个项目中,当我运行任何
grunt build
grunt service
命令时,内容(脚本标记、链接标记等)都会从我的
index.html
文件中删除。你知道为什么会这样吗?以及如何修复它。特别是从我的bower_components文件夹中导入的内容似乎正在发生,但我也有过删除字体awesome cdn的实例


如果有区别的话,我正在使用Yeoman为AngularJS开发。

可能有点明显,但是您正在编辑应用程序目录中的index.html,而不是dist/index.html副本


每当您构建时,dist文件将被您的app/index.html覆盖

我有时会遇到这种情况。更改后的零件包含在

<!-- bower:css -->
<link rel="stylesheet" href="bower_components/......" />
......
<!-- endbower -->

......


......
bower:js/css
标记中的内容是从
bower.json
生成的,因此如果js/css文件未在
bower.json
中列出,它将从
bower:js/css
中删除


好的做法是使用
bower安装--save
bower安装--save dev
来安装依赖项,它将自动更新
bower.json

我找到了另一个解决方案

这是因为您正在使用的lib的bower.json中缺少信息

调试grunt build时,我发现该文件在“wiredep”步骤中被删除

在中,你有一个关于问题的部分。 基本上,如果lib的bower.json在主节点中没有您需要的文件,那么wiredep方法将删除它

例如,角度-i18n,用于平移。 文件夹是:

angular-i18n/
           en-us.js
           pt-br.js
           bower.json
如果您查看它的bower.json:

{
  "name": "angular-i18n",
  "version": "1.6.4",
  "license": "MIT",
  "ignore": [
    "**/.*",
    "node_modules",
    "components",
    "precommit.sh"
  ]
}
添加时: 如果将此节点添加到您的bower.json,它将工作:

{
  "name": "project",
  "dependencies": {
    "angular-i18n": "^1.6.4"
  },
  "overrides" : {
    "angular-i18n" : {
      "main" : ["angular-locale_pt-br.js"]
    }
  }
}

希望这有帮助

请提供您的
grunfile.js
,以及有问题的
index.html
?没有这些,就不可能给出准确的答案。谢谢。如果有人有相同的问题,请查看中的@stephenplusplus评论
{
  "name": "project",
  "dependencies": {
    "angular-i18n": "^1.6.4"
  },
  "overrides" : {
    "angular-i18n" : {
      "main" : ["angular-locale_pt-br.js"]
    }
  }
}