咕噜咕噜:咕噜咕噜没有监视所有项目



我已经在我的工作区中安装了grunt hub,它看起来像这个

hub/
node_modules/
    grunt/
    grunt-hub/
Gruntfile.js
package.json

在Gruntfile.js中,我写了这篇文章,

module.exports = function (grunt) {
    'use strict';
    grunt.initConfig({
        pkg : grunt.file.readJSON( 'package.json' ),
        hub: {
            src: [
                'hub/*/Gruntfile.js'
            ],
            watch: {
                src: '<%= hub.src %>',
                tasks: ['watch']
            }
        }
    });
    grunt.loadNpmTasks('grunt-hub');
    grunt.registerTask('default', []);
}

我在hub目录中有四个文件,它们有自己的Gruntfile。

hub/
    project1/
        ...
        Gruntfile.js
        ...
    project2/
        ...
        Gruntfile.js
        ...
    project3/
        ...
        Gruntfile.js
        ...
    project4/
        ...
        Gruntfile.js
        ...

当我跑步的时候。。。

grunt hub

它运行得非常好;它监视我所做的所有更改,并运行我命令它们运行的方式。

唯一的问题是命令提示符,我被告知。。。

>> C:Grunthubproject1Gruntfile.js:
Running "watch" task
Waiting...
>> C:Grunthubproject2Gruntfile.js:
Running "watch" task
Waiting...
>> C:Grunthubproject3Gruntfile.js:
Running "watch" task
Waiting...

但我没有被告知正在观看project4。当我对与project4相关的文件进行更改时,什么都不会发生,而对其他一切都会发生。

我能做些什么让它也看project4?

根据https://www.npmjs.org/package/grunt-hub

肝脏对这一点有影响。以下是一些选项:

  • 将监视任务添加到hubtaskconfig(grunt.config.hub.js)中的任务列表中:

            watch: {
                    options: {
                            allowSelf: true
                    },
                    src: hubSettings.src,
                    tasks: ['watch']
            },
    

或:

  • 运行grunt hub,并将监视任务设置为默认值:grunt hub:target:watch

参考

  • grunt hub问题#28:不支持grunt contrib手表选项liverload:真正的

  • Grunt 的多模块JavaScript项目

我有以下工作方式:

    // scss files to watch ##
    watch_scss: [
        'wp-content/themes/**/*.scss', // regex to track all sass files in themes ##
        'wp-content/plugins/**/*.scss', // regex to track all sass files in plugins ##
    ],
    // grunt hub - master controller ##
    hub: {
        all: {
            options: {
                allowSelf: true,
            },
            src: [
                'Gruntfile.js', // this grunt file ##
                'wp-content/themes/**/Gruntfile.js', // in themes ##
                'wp-content/plugins/**/Gruntfile.js' // in plugins ##
            ],
            tasks: [ 'default' ]
        },
    },
    // watch task ##
    'watch': {
        // track changes to scss src files ##
        'sass': {
            'options': {
                'livereload': 1337, // dedicated port for live reload ##
                'debounceDelay': 5000, // wait a little for sass to complete ##
            },
            'files':
                '<%= watch_scss %>' // files defined in config ##
            ,
            'tasks': [
                [],  // nada ##
            ]
        },`

一定要包括咕哝的观察任务:

grunt.loadNpmTasks( 'grunt-contrib-watch' ); // Watcher ##

并定义一个默认的咕哝任务:

grunt.registerTask( 'default', [
    'watch', // watch ##
]);

确保您的个人gruntfile在监视任务上没有livereload选项,然后运行"grunt-hub:all:watch"

最新更新