Не могу заставить livereload работать в gruntfile.js

Это моя первая сборка Gruntfile.js, и все работает, но перезагрузка в реальном времени, я продолжаю получать задачу... Ошибка, когда я добавляю livereload: true, в параметры просмотра, я что-то упустил вышел или я что-то не так сделал?

Я посмотрел здесь https://github.com/gruntjs/grunt-contrib-watch#optionslivereload и последовал руководству, в котором говорится, что нужно просто добавить livereload к параметрам и установить для него значение true.

module.exports = function(grunt) {
// configure the tasks
grunt.initConfig({

//Build task
copy: {
  build: {
    cwd: 'source',
    src: [ '**', '!**/*.less', '!**/*.coffee', '!**/*.jade' ],
    dest: 'build',
    expand: true
  },
},

// Clean task
clean: {
  build: {
    src: [ 'build' ]
  },
  stylesheets: {
      src: [ 'build/**/*.css', '!build/application.css' ]
  },
  scripts: {
    src: [ 'build/**/*.js', '!build/application.js' ]
  },
},

// Less task
less: {
  build: {
    options: {
      linenos: true,
      compress: false
    },
    files: [{
      expand: true,
      cwd: 'source',
      src: [ '**/*.less' ],
      dest: 'build',
      ext: '.css'
    }]
  }
},

// Autoprefixer task
autoprefixer: {
  build: {
    expand: true,
    cwd: 'build',
    src: [ '**/*.css' ],
    dest: 'build'
  }
},

// CSS Minify task
cssmin: {
  build: {
    files: {
      'build/application.css': [ 'build/**/*.css' ]
    }
  }
},

// Coffee task
coffee: {
  build: {
    expand: true,
    cwd: 'source',
    src: [ '**/*.coffee' ],
    dest: 'build',
    ext: '.js'
  }
},


// Uglify
uglify: {
  build: {
    options: {
      mangle: false
    },
    files: {
      'build/application.js': [ 'build/**/*.js' ]
    }
  }
},

// Html task
jade: {
  compile: {
    options: {
      data: {}
    },
    files: [{
      expand: true,
      cwd: 'source',
      src: [ '**/*.jade' ],
      dest: 'build',
      ext: '.html'
    }]
  }
},


// Watch task
watch: {
  stylesheets: {
    files: 'source/**/*.less',
    tasks: [ 'stylesheets' ]
  },
  scripts: {
    files: 'source/**/*.coffee',
    tasks: [ 'scripts' ]
  },
  jade: {
    files: 'source/**/*.jade',
    tasks: [ 'jade' ]
  },
  copy: {
    files: [ 'source/**', '!source/**/*.less', '!source/**/*.coffee', '!source/**/*.jade' ],
    tasks: [ 'copy' ]
  }
},

// Connect to server task
connect: {
  server: {
    options: {
      port: 4000,
      base: 'build',
      hostname: '*'
      livereload: true,
    }
  }
}

});


// load the tasks
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jade');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');

// builds and cleans the task
grunt.registerTask(
  'build',
  'Compiles all of the assets and copies the files to the build directory.',
  [ 'clean:build', 'copy', 'stylesheets', 'scripts', 'jade' ]
);

// Adds stylesheet to the task
grunt.registerTask(
  'stylesheets',
  'Compiles the stylesheets.',
  [ 'less', 'autoprefixer', 'cssmin', 'clean:stylesheets' ]
);
  // Adds javascript to the task
  grunt.registerTask(
    'scripts',
    'Compiles the JavaScript files.',
    [ 'coffee', 'uglify', 'clean:scripts' ]
  );

  //watches and connects to the server
  grunt.registerTask(
    'default',
    'Watches the project for changes, automatically builds them and runs a server.',
    [ 'build', 'connect', 'watch']
  );
};

person mayhemds    schedule 24.04.2014    source источник


Ответы (1)


Вам нужно добавить опцию в конфигурацию для задачи наблюдения. В настоящее время у вас есть настройка в задаче подключения, а не в задаче просмотра. Попробуйте что-то вроде этого:

watch: {
  options: {
    livereload:true,
  },
  stylesheets: {
    files: 'source/**/*.less',
    tasks: [ 'stylesheets' ]
  },
  scripts: {
    files: 'source/**/*.coffee',
    tasks: [ 'scripts' ]
  },
  jade: {
    files: 'source/**/*.jade',
    tasks: [ 'jade' ]
  },
  copy: {
    files: [ 'source/**', '!source/**/*.less', '!source/**/*.coffee', '!source/**/*.jade' ],
    tasks: [ 'copy' ]
  }
},

Вам также нужно будет удалить его из задачи подключения

person Guy    schedule 24.04.2014
comment
это сработало, но теперь я получаю фатальную ошибку: порт 35729 уже используется другим процессом? - person mayhemds; 24.04.2014
comment
Вы можете указать новый порт, используя настройки livereload. См. примеры настроек здесь: github.com/gruntjs/grunt-contrib-watch#optionslivereload< /а> - person Guy; 24.04.2014