Gruntjs 咕噜声手表中断不与杰基尔一起工作

Gruntjs 咕噜声手表中断不与杰基尔一起工作,gruntjs,jekyll,grunt-contrib-watch,Gruntjs,Jekyll,Grunt Contrib Watch,所以我是Grunt的新手,一直在尝试为it和Jekyll实现一个工作流。因此,我有一个watch任务正在运行,但在再次尝试启动Jekyll之前,它似乎无法中断当前的服务任务,因为我得到了一个关于端口绑定的错误,特别是Jekyll 2.0.3 |错误:地址已在使用中-bind(2) 可能是我做了一些愚蠢的事情或者不理解一些事情,但是有人有什么想法吗?这是我的Grunfile文件: module.exports = function( grunt ) { // load time-grunt and

所以我是Grunt的新手,一直在尝试为it和Jekyll实现一个工作流。因此,我有一个watch任务正在运行,但在再次尝试启动Jekyll之前,它似乎无法中断当前的服务任务,因为我得到了一个关于端口绑定的错误,特别是Jekyll 2.0.3 |错误:地址已在使用中-bind(2)

可能是我做了一些愚蠢的事情或者不理解一些事情,但是有人有什么想法吗?这是我的Grunfile文件:

module.exports = function( grunt ) {
// load time-grunt and all grunt plugins found in the package.json
require( 'time-grunt' )( grunt );
require( 'load-grunt-tasks' )( grunt );
grunt.initConfig({
    csslint : {
        test : {
            options : {
                import : 2
            },
            src : [ 'css/main.css' ]
        }
    },

    cssmin : {
        dist : {
            src : 'css/main.css',
            dest : 'css/main.min.css'
        }
    },

    shell : {
        jekyllBuild : {
            command : 'glynn'
        },
        jekyllServe : {
            command : 'jekyll serve'
        }
    },

    watch : {
        files : [ '_layouts/*.html',
                  '_posts/*.md',
                  'css/main.css',
                  '_config.yml',
                  'index.html',
                  '404.html' ],
        tasks : [ 'cssmin',
                  'shell:jekyllServe' ],
        options : {
            spawn : true,
            interrupt : true,
            atBegin : true,
            debounceDelay: 250
        }
    }
});

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-csslint');
grunt.loadNpmTasks('grunt-shell');

// register custom grunt tasks
grunt.registerTask( 'lintcheck', [ 'cssmin','csslint', 'shell:jekyllServe' ] )
grunt.registerTask( 'qbuild', [ 'cssmin', 'shell:jekyllServe' ] )
grunt.registerTask( 'deploy', [ 'cssmin', 'shell:jekyllBuild' ] )
};

任何帮助都将不胜感激。

我正在开发一个具有类似工作流程的网站,但使用的是Gulp而不是Grunt。我将默认的jekyll服务器与browserSync进行了交换,browserSync在进行更改时也会自动重新加载页面(在开发中很有用)。是一个示例Gulp构建文件;可以生成Grunt等价项。

您出现错误,因为您尝试多次运行
jekyll serve
(而服务器已在运行)。正如您在文档中所读到的,
jekyllserve
在localhost:4000()上运行开发服务器,因此您只能在特定端口上同时启动一个开发服务器。之后,当某些文件发生更改时,您只需将jekyll重建到./\u站点。您可以使用
jekyll build
来实现这一点

我修改了你的GrunFile:

module.exports = function( grunt ) {
// load time-grunt and all grunt plugins found in the package.json
require( 'time-grunt' )( grunt );
require( 'load-grunt-tasks' )( grunt );
grunt.initConfig({
    csslint : {
        test : {
            options : {
                import : 2
            },
            src : [ 'css/main.css' ]
        }
    },

    cssmin : {
        dist : {
            src : 'css/main.css',
            dest : 'css/main.min.css'
        }
    },

    shell : {
        jekyllBuildLocal : {
            command : 'jekyll build'
        },
        jekyllBuild : {
            command : 'glynn'
        },
        jekyllServe : {
            command : 'jekyll serve'
        }
    },

    watch : {
        files : [ '_layouts/*.html',
                  '_posts/*.md',
                  'css/main.css',
                  '_config.yml',
                  'index.html',
                  '404.html' ],
        tasks : [ 'cssmin',
                  'shell:jekyllBuildLocal' ],
        options : {
            spawn : true,
            interrupt : true,
            atBegin : true,
            debounceDelay: 250
        }
    }
});

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-csslint');
grunt.loadNpmTasks('grunt-shell');

// register custom grunt tasks
grunt.registerTask( 'lintcheck', [ 'cssmin','csslint', 'shell:jekyllBuildLocal' ] )
grunt.registerTask( 'qbuild', [ 'cssmin', 'shell:jekyllBuildLocal' ] )
grunt.registerTask( 'deploy', [ 'cssmin', 'shell:jekyllBuild' ] )
};
对于开发,我建议您运行:

  • grunt shell:jekyllServe
  • grunt watch
    (我猜是在其他终端窗口中)

  • 这应该可以正常工作

    感谢您的帮助-尽管它没有解决问题,但它给了我一个完美的解决方法。非常感谢!