0
votes

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.

2
What does the output look like? Always include output, since many times the assumptions regarding what the output means are wrong.Creynders
Not saying that is the case here, just that it might be.Creynders

2 Answers

4
votes

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!

2
votes

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'
]);