watch infinite loop

I've set up a project with grunt watch (for coffee and scss files essentially). I've got a infinite loop issue.

here is my Gruntfile.js file:

'use strict';

module.exports = function(grunt) {

    require('load-grunt-tasks')(grunt);

    grunt.initConfig({

        coffeelint: {
            dist: ['coffee/*.coffee'],
            server: ['coffee/*.coffee']
        },

        coffee: {
            dist: {
                compile: {
                    files: {
                        'js/hscroll.js': 'coffee/*.coffee'
                    }
                }
            },
            server: {
                compileWithMaps: {
                    options: {
                        bare: true,
                        sourceMap: true
                    },
                    files: {
                        'js/hscroll.js': 'coffee/*.coffee',
                    }
                }
            }
        },

        uglify: {
            dist: {
                files: {
                    'js/hscroll.min.js': ['js/hscroll.js']
                }
            }
        },

        watch: {
            coffee: {
                files: ['coffee/*.coffee'],
                tasks: ['coffeelint:server', 'coffee:server']
            },
            compass: {
                files: ['sass/{,*/}*.{scss,sass}'],
                tasks: ['compass:server']
            }
        },

        compass: {
            dist: {
                options: {
                    sassDir: 'sass',
                    cssDir: 'stylesheets',
                }
            },
            server: {
                options: {
                    debugInfo: true,
                    sassDir: '/sass',
                    cssDir: '.tmp',
                    relativeAssets: false,
                    assetCacheBuster: false
                }
            }
        },

        clean: {
            dist: {
                files: [{
                    dot: true,
                    src: '.tmp'
                }]
            },
            server: '.tmp'
        },
    });

    grunt.registerTask('dist', ['clean:dist', 'coffeelint:dist', 'coffee:dist', 'compass:dist', 'uglify:dist']);

    grunt.registerTask('watch', [
        'clean:server',
        'coffeelint:server',
        'coffee:server',
        'compass:server',
        'watch'
    ]);
};

It loops when I launch 'grunt watch', I don't unserstand why?

Perhaps a newbie questions, but any help will be welcome....

Thanks.

My folder structure is: hscroll> css .sass.cache (I used compass) coffee css sass stylesheets

grunt dist works perfectly.

Thanks.


I think I've found the issue. By registering a task called watch which itself call the watch task. I've created the loop. I just deleted

grunt.registerTask('watch', [
        'clean:server',
        'coffeelint:server',
        'coffee:server',
        'compass:server',
        'watch'
]);

and added the right tasks in the watch config and now it works!


you can rename the original "watch" task of the plugin to an own for example "watchfiles". The following should be working:

    watchfiles: {
        coffee: {
            files: ['coffee/*.coffee'],
            tasks: ['coffeelint:server', 'coffee:server']
        },
        compass: {
            files: ['sass/{,*/}*.{scss,sass}'],
            tasks: ['compass:server']
        }

...

grunt.renameTask('watch',
    'watchfiles');

grunt.registerTask('watch', [
    'clean:server',
    'coffeelint:server',
    'coffee:server',
    'compass:server',
    'watchfiles'
]);
链接地址: http://www.djcxy.com/p/78970.html

上一篇: Grunt不更新主scss文件

下一篇: 观看无限循环