我是自耕农,咕噜咕噜和凉亭的新人。 我用自耕农做了一个有角度的应用程序,现在我尝试编辑gruntfile.js。但实时重新加载仅适用于“应用程序”中的文件。 - 文件夹。在' app / views /'等文件夹中它不会重新加载我的页面。 grunt服务器注意到更改,我可以在控制台输出中看到这一点(文件" app \ views \ partial1.html"已更改。)但没有实时重载。 任何人都可以告诉我如何解决这个问题。我google了很多但不知怎的,我没有得到这个修复。 这是我在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}'
]
}
事先得到你的帮助!!
答案 0 :(得分:3)
将所有{,*/}
大括号扩展名替换为**/
。所以代码应该是这样的:
// 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很好地描述了这个:
所有大多数人都需要知道的是
foo/*.js
将匹配foo /子目录中以.js结尾的所有文件,但foo/**/*.js
将匹配foo /子目录中以.js结尾的所有文件,它的所有子目录。