我是 yeoman、grunt 和 Bower 的新手。 我用 yeoman 制作了一个 Angular 应用程序,现在我尝试编辑 gruntfile.js。但实时重新加载仅适用于“app”文件夹中的文件。在“app/views/”等文件夹中,它不会实时重新加载我的页面。 grunt 服务器注意到了更改,我可以在控制台输出中看到这一点(文件“app\views\partial1.html”已更改。),但没有发生实时重新加载。 谁能告诉我如何解决这个问题。我用谷歌搜索了很多,但不知何故我没有解决这个问题。 这是我在 gruntfile.js 中的监视部分:
// Watches files for changes and runs tasks based on the changed files
watch: {
bower: {
files: ['bower.json'],
tasks: ['wiredep']
},
js: {
files: ['<%= yeoman.app %>/scripts/{,*/}*.js'],
tasks: ['newer:jshint:all'],
options: {
livereload: '<%= connect.options.livereload %>'
}
},
jsTest: {
files: ['test/spec/{,*/}*.js'],
tasks: ['newer:jshint:test', 'karma']
},
styles: {
files: ['<%= yeoman.app %>/styles/{,*/}*.css'],
tasks: ['newer:copy:styles', 'autoprefixer']
},
gruntfile: {
files: ['Gruntfile.js']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= yeoman.app %>/{,*/}*.html',
'.tmp/styles/{,*/}*.css',
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
提前感谢您的帮助!!
最佳答案
将所有 {,*/}
大括号扩展替换为 **/
。所以代码应该如下所示:
// Watches files for changes and runs tasks based on the changed files
watch: {
bower: {
files: ['bower.json'],
tasks: ['wiredep']
},
js: {
files: ['<%= yeoman.app %>/scripts/**/*.js'],
tasks: ['newer:jshint:all'],
options: {
livereload: '<%= connect.options.livereload %>'
}
},
jsTest: {
files: ['test/spec/**/*.js'],
tasks: ['newer:jshint:test', 'karma']
},
styles: {
files: ['<%= yeoman.app %>/styles/**/*.css'],
tasks: ['newer:copy:styles', 'autoprefixer']
},
gruntfile: {
files: ['Gruntfile.js']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= yeoman.app %>/**/*.html',
'.tmp/styles/**/*.css',
'<%= yeoman.app %>/images/**/*.{png,jpg,jpeg,gif,webp,svg}'
]
}
仅供引用,**
是一种通配模式。 Grunt documentation很好地描述了这一点:
All most people need to know is that
foo/*.js
will match all files ending with .js in the foo/ subdirectory, butfoo/**/*.js
will match all files ending with .js in the foo/ subdirectory and all of its subdirectories.
关于javascript - gruntserve - 实时重新加载仅适用于 app/*.html,但不适用于 app/views/*.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25097749/