grunt serve - live reload仅适用于app / * .html,但不适用于app / views / * .html

时间:2014-08-02 17:42:02

标签: javascript angularjs gruntjs

我是自耕农,咕噜咕噜和凉亭的新人。 我用自耕农做了一个有角度的应用程序,现在我尝试编辑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}'
            ]
        }
事先得到你的帮助!!

1 个答案:

答案 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结尾的所有文件,它的所有子目录。

相关问题