简体   繁体   English

添加新js后,yeoman / grunt-usemin不更新index.html

[英]yeoman/grunt-usemin not updating index.html after new js has been added

I am using yeoman with the angular generator for a web app on windows7. 我在Windows7上使用带有角度生成器的yeoman用于web应用程序。 After running yo angular I run grunt to build the app for deployment. 在运行yo angular之后,我运行grunt来构建应用程序以进行部署。 My index.html file in the dist folder is changed accordingly with the css and js files that was concatenated and minified. 我在dist文件夹中的index.html文件相应地更改了连接和缩小的css和js文件。

When I add a new js file to index.html for example 例如,当我向index.html添加新的js文件时

<script src="bower_components/json3/lib/json3.js"></script>

and I run grunt again to build; 我再次咕噜咕噜地建造; the index.html file no longer changes the css aan js files to the minified ones, it basically shows exactly the same as the index.html in the app directory. index.html文件不再将css aan js文件更改为缩小文件,它基本上与app目录中的index.html完全相同。

I also tried putting the json3.js inside the build:js comments: 我也尝试将json3.js放在build中:js comments:

 <!-- build:js scripts/json.js -->
 <script src="bower_components/json3/lib/json3.js"></script>
 <!-- endbuild -->

Is there something I am missing here? 这里有什么我想念的吗? Must I change something in the grunt file like the usemin section? 我必须在grunt文件中更改某些内容,例如usemin部分吗?

I repeatedly bumped into this problem and have found a solution in my case. 我一再遇到这个问题,并在我的案例中找到了解决方案。

I am using vs 2012 to create my HTML and cmd for the grunt tasks. 我使用vs 2012为grunt任务创建我的HTML和cmd。 It seems that my Line endings were not correct, so I changed them to Unix (LF) and grunt-usemin did its thing. 似乎我的Line结尾不正确,所以我将它们改为Unix(LF)并且grunt-usemin做了它的事情。 When settings the line endings to Windows (CR LF) grunt-usemin don't update the index.html page correctly. 将行结尾设置为Windows(CR LF)时,grunt-usemin不会正确更新index.html页面。

Hope this helps somebody! 希望这有助于某人!

Note that your custom JavaScripts are included from build:js({.tmp,app}) section, that's why they get minified in a single file. 请注意,您的自定义JavaScripts包含在build:js({.tmp,app})部分中,这就是它们在单个文件中缩小的原因。
I'm not suggesting putting libraries obtained by bower to build:js({.tmp,app}) - see remarks of: https://stackoverflow.com/a/19034513/1432478 . 我并不是建议将bower获得的库build:js({.tmp,app}) - 请参阅: https//stackoverflow.com/a/19034513/1432478

A good idea might be looking at grunt's cdnify task. 一个好主意可能是关注grunt的cdnify任务。
json3 CDN json3 CDN

I had the exact same problem. 我有同样的问题。 The only way that I could find to fix it was in the Gruntfile under the htmlmin task. 我能找到修复它的唯一方法是在htmlmin任务下的htmlmin

When the index.html file was not changing, my htmlmin task was as follows: 当index.html文件没有改变时,我的htmlmin任务如下:

htmlmin: {
  dist: {
    options: {
      //options
    },
    files: [{
      expand: true,
      cwd: '<%= yeoman.app %>',
      src: ['*.html', 'views/{,*/}*.html'],
      dest: '<%= yeoman.dist %>'
    }]
  }
}

If I simply removed the *.html part in html:files:src , the build worked fine. 如果我只是删除了html:files:src*.html部分,那么构建工作正常。 My newer htmlmin task looked like this: 我的新htmlmin任务看起来像这样:

htmlmin: {
  dist: {
    options: {
      //options
    },
    files: [{
      expand: true,
      cwd: '<%= yeoman.app %>',
      src: ['views/{,*/}*.html'],
      dest: '<%= yeoman.dist %>'
    }]
  }
}

Hopefully this helps someone. 希望这有助于某人。 It took me a while to figure out why the index.html file wasn't being edited correctly. 我花了一段时间才弄清楚为什么index.html文件没有被正确编辑。

I was having the same issue with not being able to add angular-route and angular-animate - by that I mean the reference to the files - their script tags - were not being saved to the index.html file. 我有同样的问题,无法添加角度路由和角度动画 - 我的意思是对文件的引用 - 他们的脚本标签 - 没有保存到index.html文件。

I discovered it was because I had entered their script tags before the tag in my index.html file. 我发现这是因为我在index.html文件中的标签之前输入了他们的脚本标签。 After putting them immediately after, it worked fine. 之后立即放置它们,它工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM