grunt-watch无限循环

时间:2014-04-07 19:14:39

标签: sass gruntjs infinite-loop

我已经设置了一个带有grunt watch的项目(基本上是用于咖啡和scss文件)。我有一个无限循环问题。

这是我的Gruntfile.js文件:

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

当我启动' grunt watch'时,它会循环,我不知道为什么?

也许是一个新手问题,但欢迎任何帮助......

感谢。

我的文件夹结构是: 使用hscroll>   CSS   .sass.cache(我用罗盘)   咖啡   CSS   上海社会科学院   样式表

grunt dist完美无缺。

感谢。

2 个答案:

答案 0 :(得分:4)

我想我已经找到了这个问题。通过注册名为watch的任务,该任务本身称为监视任务。我创建了循环。我刚刚删除了

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

并在watch配置中添加了正确的任务,现在它可以正常工作!

答案 1 :(得分:2)

你可以重命名原作" watch"插件的任务,例如,#34; watchfiles"。以下应该有效:

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