Grunt serve - live reload只适用于app/*.html,而不适用于app/views/*.htm

grunt serve - live reload only works in app/*.html but not in app/views/*.html

本文关键字:适用于 app 不适用 views htm html serve live Grunt reload      更新时间:2023-09-26

我刚学会自耕农、咕噜咕噜和低头。我用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}'
        ]
    }

作为参考,**是一种globbing pattern。Grunt文档很好地描述了这一点:

大多数人需要知道的是foo/*.js将匹配foo/子目录中以.js结尾的所有文件,但foo/**/*.js将匹配foo/子目录及其所有子目录中以.js结尾的所有文件。