与Grunt同时运行`watch`&`nodemon`

Jon*_*tes 6 watch node.js jshint gruntjs nodemon

我刚刚开始使用Grunt,并希望每次修改文件时使用[GitHub页面]运行grunt-contrib-watch [GitHub页面] lint我的JavaScript(使用grunt-contrib-jshint [GitHub页面])并运行grunt-nodemon [GitHub页面],同时使用grunt-concurrent [GitHub页面].

据我所知(我显然没有)我的Gruntfile应该:

  1. concurrent默认运行
  2. concurrent 运行 watch
  3. watchjshint每次修改文件时都会运行

Gruntfile.js

module.exports = function (grunt) {
    grunt.initConfig({
        concurrent: {
            dev: [
                'watch'
            ],
            options: {
                logConcurrentOutput: true
            }
        },
        jshint: {
            server: [
                '**/*.js',
                '!node_modules/**/*.js'
            ],
            options: {
                node: true
            }
        },
        watch: {
            all: [
                '**/*/.js',
                '!node_modules/**/*.js'
            ],
            tasks: [
                'jshint'
            ]
        }
    });

    grunt.loadNpmTasks('grunt-concurrent');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.registerTask('default', [
        'concurrent:dev'/*,
        'jshint',
        'watch'*/
    ]);
};

    grunt.loadNpmTasks('grunt-concurrent');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.registerTask('default', [
        'concurrent:dev'
    ]);
};
Run Code Online (Sandbox Code Playgroud)

NB我还没有添加grunt-nodemon到混音中.

它看起来像是concurrent在运行,watch但是当我修改文件时,它似乎jshint没有运行.我当然不会在终端中获得任何输出(我认为logConcurrentOutput: true这样做).

这是我在终端中获得的输出:

Running "concurrent:dev" (concurrent) task
Running "watch" task
Waiting...    


Done, without errors.
Run Code Online (Sandbox Code Playgroud)

我还想jshint在我第一次运行default任务时运行(以及修改文件时).

任何人都可以了解我的错误吗?

谢谢!

Jon*_*tes 6

watch如果没有找到"观察"的文件,该任务将退出; 按照这个问题.

为了轻松告诉watch观看与jshint任务相同的文件,我使用Grunt的模板引擎来引用与任务相同Array的文件jshint.

然后我添加jshint到要运行的并发任务列表中,这样它最初会运行并且当我修改文件时(带watch).

这是我的工作Gruntfile:

module.exports = function (grunt) {
    grunt.initConfig({
        concurrent: {
            dev: [
                'jshint',
                'watch'
            ],
            options: {
                logConcurrentOutput: true
            }
        },
        jshint: {
            server: [
                '**/*.js',
                '!node_modules/**/*.js'
            ],
            options: {
                node: true
            }
        },
        watch: {
            files: '<%= jshint.server %>',
            tasks: [
                'jshint'
            ]
        }
    });

    grunt.loadNpmTasks('grunt-concurrent');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.registerTask('default', [
        'concurrent'
    ]);
};
Run Code Online (Sandbox Code Playgroud)