Grunt:Livereload不起作用

每次我尝试使用grunt watch的live reload选项时,我都会遇到这个问题。 无论使用哪个端口,我都会收到“致命错误:端口xxxx已被另一进程使用”。 我列出了所有正在使用的端口,select一个没有出现在列表中的随机数字并没有帮助:它将xxxxreplace为grunt文件中最后使用的任何端口。

我的grunt文件本身:

module.exports = function (grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), watch: { options: { livereload: true }, js: { files: ['.dev/**/*.js'], tasks: ['concat', 'uglify', 'watch'], }, scss: { files: ['./dev/scss/*.scss'], tasks: ['sass', 'concat', 'watch'], options: { reload: true, livereload: false, } }, html: { files: ['./dev/**/*.html', 'watch'], tasks: ['copy', 'watch'], }, grunt: { files: ['Gruntfile.js'], tasks: ['watch'], }, }, concat: { js: { src: ['dev/js/script1.js', 'dev/js/script2.js'], dest: 'dev/js/script.js', }, css: { src: ['./dev/css/nav.css', './dev/css/anim.css', './dev/css/style.css'], dest: './dist/css/style.css', }, }, uglify: { build: { src: 'dev/js/script.js', dest: 'dist/js/script.min.js' } }, sass: { // Task dev: { // Target files: { // Dictionary of files './dev/css/style.css': './dev/scss/style.scss', // 'destination': 'source' }, tasks: ['copy'], } }, copy: { main: { expand: true, cwd: './dev/html', src: '*.html', dest: './dist/html/' }, }, }); // Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-contrib-sass'); // Default task(s). grunt.registerTask('default', ['concat', 'uglify', 'sass', 'copy', 'watch']); }; 

我对npm,grunt等还是一个新东西,并且也使用了Yeoman来解决这个问题。 有一些应用程序可能会自动侦听每个端口(我正在使用Webstorm)吗? 但是,当我closures它,使用崇高和terminal,它不断说每个随机端口已被使用

看起来像你recursion调用手表..

以gruntfile的这部分为例:

 watch: { // hey grunt, you now know of a task called 'watch' .... html: { files: ['./dev/**/*.html', 'watch'], // here are the files to watch tasks: ['copy', 'watch'], // and oh, hey, when you run watch, make // sure to run watch again, recursively, forever } 

我想你可以看到这是怎么回事 您的端口正在使用,因为您的监视任务在重新运行时已经在运行。 您不需要在手表的每个部分注册“手表”作为任务。 希望帮助:)