javascript - gruntserve - 实时重新加载仅适用于 app/*.html,但不适用于 app/views/*.html

标签 javascript angularjs gruntjs

我是 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, but foo/**/*.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/

相关文章:

javascript - 从/到 Javascript 字符串从 Go int64/uint64 序列化反序列化

javascript - Jasmine 测试 Backbone 查看事件

javascript - 是否可以在 Visual Studio Pre Build 事件中添加监视 ng build 的更改?

javascript - 当路由到特定路由 Angularjs 时运行函数?

javascript - 运行 grunt build 命令时 Gruntfile 不工作

javascript - 等待退出的 Grunt 任务

javascript - 带有 .parent() 和动态选择器的 jQuery .on()

javascript - React-Redux 中的页面加载时未调度操作

javascript - 将数据从 Angular 形式传递到另一个 Controller

javascript - 如何让 Grunt-Contrib-Jasmine 执行规范并加载依赖项?