运行 与 'nodemon' 和 'watch' 任务并发时的无限循环

Infinite loop when running grunt-concurrent with 'nodemon' and 'watch' tasks

我正在尝试使用 grunt-concurrent task to run grunt-nodemon 来观看我的 js 脚本,并同时使用 watch 在我的文件发生变化时仍然 concatuglify

当我在命令行上 运行 grunt 时,我得到以下无限循环:

Running "watch" task
Waiting...
Verifying property watch.concurrent.files exists in config...ERROR >> Unable to process task.
Warning: Required config property "watch.concurrent.files" missing.

停止这种不断涌现的消息的唯一方法是退出命令行。

这是我的 g运行t 文件:

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    concat: {
    dist: {
        src: [
            'public/js/libs/*.js',
        ],
        dest: 'public/js/build/production.js',
        }
    },
    uglify: {
        build: {
            src: 'public/js/build/production.js',
            dest: 'public/js/build/production.min.js'
        }
    },
    css: {
      files: ['css/*.scss'],
      tasks: ['sass'],
      options: {
          spawn: false,
      }
    },
    sass: {
    dist: {
        options: {
            style: 'compressed'
        },
        files: {
            'public/css/build/main.css': 'public/css/main.scss'
        }
      }
    },
    nodemon: {
      dev: {
        script: './start.js'
      }
    },
    watch: {
    scripts: {
        files: ['js/*.js'],
        tasks: ['concat','uglify'],
        options: {
            spawn: false,
        },
    },
    concurrent: {
        target: {
            tasks: ['nodemon', 'watch'],
            options: {
                logConcurrentOutput: true
            }
        }
    },
  }
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-nodemon');
grunt.loadNpmTasks('grunt-concurrent');
grunt.registerTask('default', ['concat','uglify','sass','watch','nodemon','concurrent:target']);
};

这是我的package.json:

{
  "name": "**** *****",
  "version": "1.0.0",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-concurrent": "^2.3.1",
    "grunt-contrib-concat": "^1.0.1",
    "grunt-contrib-imagemin": "^1.0.1",
    "grunt-contrib-sass": "^1.0.0",
    "grunt-contrib-uglify": "^2.3.0",
    "grunt-contrib-watch": "^1.0.0",
    "grunt-nodemon": "^0.4.2",
    "webpack-dev-server": "^2.9.7"
  },
  "description": "",
  "main": "app.js",
  "scripts": {
    "start": "nodemon ./start.js"
  },
  "author": "**** *******",
  "license": "ISC",
  "dependencies": {
    "cookie-parser": "^1.4.3",
    "dotenv": "^4.0.0",
    "express": "^4.16.2",
    "mongod": "^2.0.0",
    "mongoose": "^4.13.7",
    "nodemon": "^1.14.1",
    "normalize.css": "^6.0.0"
  }
}

编辑:解决了无限循环

我仍然不认为我已经完全解决了我的问题,但我更近了一步...

我的watch任务中有语法error/omission:

    watch: {
    scripts: {
        files: ['js/*.js'],
        tasks: ['concat','uglify'],
        options: {
            spawn: false,
        },
    },

应该包括

watch: {
scripts: {
    files: ['js/*.js'],
    tasks: ['concat','uglify'],
    options: {
        spawn: false,
    },
},
css: {
      files: ['css/*.scss'],
      tasks: ['sass'],
      options: {
          spawn: false,
      },
    }
},

这妨碍了我的监视任务 运行 正确执行。我目前没有无限循环了。相反,我的命令行呈现这个:

Running "concat:dist" (concat) task

Running "uglify:build" (uglify) task
>> 1 file created 797.64 kB → 378.58 kB

Running "sass:dist" (sass) task

Running "nodemon:dev" (nodemon) task
[nodemon] 1.14.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node ./start.js`
Express running → PORT 7777

看起来 nodemon 是 运行ning,但它根本没有说明我的 watch 任务,当我更改 SCSS 文件时,没有任何反应.我显然希望 grunt-concurrent 到 运行 同时完成我的 nodemonwatch 任务。

如果命令行成功执行且没有任何错误,是否应该说一些不同的东西?

谢谢!

grunt.registerTask 代码中删除 nodemonwatch 解决了问题:

grunt.registerTask('default', ['concat','uglify','sass','watch','nodemon','concurrent:target']);

是 运行ning nodemon 并作为默认任务观看, 然后 试图 运行 concurrent:target 只是 运行 ning concurrent:target 无论如何都会同时有 运行 nodemonwatch

现在终端呈现:

Running "concat:dist" (concat) task

Running "uglify:build" (uglify) task
>> 1 file created 797.64 kB → 378.58 kB

Running "sass:dist" (sass) task

Running "concurrent:target" (concurrent) task
    Running "watch" task
    Waiting...
    Running "nodemon:dev" (nodemon) task
    [nodemon] 1.14.1
    [nodemon] to restart at any time, enter `rs`
    [nodemon] watching: *.*
    [nodemon] starting `node ./start.js`
    Express running → PORT 7777

看起来正确!

经过更正的新 G运行t 文件如下所示:

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    concat: {
    dist: {
        src: [
            'public/js/libs/*.js',
        ],
        dest: 'public/js/build/production.js',
        }
    },
    uglify: {
        build: {
            src: 'public/js/build/production.js',
            dest: 'public/js/build/production.min.js'
        }
    },
    sass: {
    dist: {
        options: {
            style: 'compressed'
        },
        files: {
            'public/css/build/main.css': 'public/css/main.scss'
        }
      }
    },
    concurrent: {
        target: {
            tasks: ['nodemon', 'watch'],
            options: {
                logConcurrentOutput: true
            }
        }
    },
    watch: {
    scripts: {
        files: ['./public/js/*.js'],
        tasks: ['concat','uglify'],
        options: {
            spawn: false,
        },
    },
    css: {
          files: ['./public/css/*.scss'],
          tasks: ['sass'],
          options: {
              spawn: false,
          },
        }
    },
    nodemon: {
      dev: {
        script: './start.js'
      }
    },
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-nodemon');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['concat','uglify','sass','concurrent:target']);

};