grunt-contrib-watch livereload 35729 livereload.js无法加载

我正在运行grunt-contrib-watch 0.6.1,并在我的gruntfile.js中包含了livereload块。 我还在我的html中包含了livereload.js调用:

<script type="text/javascript" src="http://myste.com:35729/livereload.js"></script> 

当我使用我的开发环境运行服务器似乎一切似乎开始正确。

 grunt dev Running "env:dev" (env) task Running "concurrent:dev" (concurrent) task Running "nodemon:dev" (nodemon) task [nodemon] v1.2.1 [nodemon] to restart at any time, enter `rs` [nodemon] watching: *.* [nodemon] starting `node server.js` Application Started on port 3000 

当我进行更改时,可以看到服务器在我的ssh控制台中重新加载,但livereload.js无法加载:

当我去的应该是http://myste.com:35729/livereload.js的端口位置,我得到的标准“网页不可用”的回应。 在http://myste.com:35729/上似乎也没有运行服务器。

我也包括我的gruntfile.js完整性

 'use strict'; module.exports = function (grunt) { var watchFiles = { serverViews: ['app/views/**/*.*'], serverJS: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js'], clientViews: ['public/views/**/*.html'], clientJS: ['public/js/**/*.js'], clientSASS: 'public/styles/sass/**/*.{scss,sass}', clientCSS: ['public/styles/css/**/*.css'] }; grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), env: { dev: { NODE_ENV: 'development' }, prod: { NODE_ENV: 'production' } }, watch: { serverViews: { files: watchFiles.serverViews, options: { livereload: true } }, serverJS: { files: watchFiles.serverJS, tasks: ['jshint'], options: { livereload: true } }, clientViews: { files: watchFiles.clientViews, options: { livereload: true, } }, clientJS: { files: watchFiles.clientJS, tasks: ['jshint'], options: { livereload: true } }, clientSASS: { files: watchFiles.clientSASS, tasks: ['sass:dev'], options: { livereload: true, spawn: false } }, clientCSS: { files: watchFiles.clientCSS, tasks: ['csslint'], options: { livereload: true } }, }, nodemon: { dev: { script: 'server.js' } }, nodeunit: { dev: { all: ['app/test/**/*_test.js'], options: { reporter: 'tap', reporterOutput: 'tests.tap', reporterOptions: { output: 'outputdir' } } } }, jshint: { dev: { all: { src: watchFiles.clientJS.concat(watchFiles.serverJS), options: { jshintrc: true } } } }, uglify: { prod: { my_target: { files: { 'public/js/all.min.js': ['public/js/library/jquery.js', 'public/js/library/modernizr.js', 'public/js/library/selectivizr.js', 'public/js/library/delfin.js'] } } } }, sass: { dev: { options: { style: 'expanded' }, files: { 'public/styles/css/style.css': 'public/styles/scss/style.scss' // 'destination': 'source' } } }, cssmin: { prod: { files: { 'public/styles/css/style.min.css': 'public/styles/css/style.css' } } }, csslint: { dev: { options: { csslintrc: '.csslintrc', }, all: { src: watchFiles.clientCSS } } }, concurrent: { dev: { target: { tasks: ['nodemon', 'watch'], options: { logConcurrentOutput: true } } } } }); grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTasks('grunt-contrib-csslint'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-nodeunit'); grunt.loadNpmTasks('grunt-contrib-sass'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-express-server'); grunt.loadNpmTasks('grunt-concurrent'); grunt.loadNpmTasks('grunt-nodemon'); grunt.loadNpmTasks('grunt-env'); grunt.registerTask('dev', ['env:dev', 'concurrent', 'nodemon', 'watch', 'jshint', 'nodeunit', 'sass']); grunt.registerTask('prod', ['env:prod', 'cssmin', 'uglify', 'nodemon']); }; 

您尝试运行nodemonwatch两次任务。 首先,当你运行concurrent任务时,第二次当你自己调用。

将您的concurrent任务configuration更改为

 concurrent: { tasks: ['nodemon', 'watch'], options: { logConcurrentOutput: true } }, 

并从grunt dev声明中移除额外的任务:

 grunt.registerTask('dev', ['env:dev', 'concurrent', 'jshint', 'nodeunit', 'sass']);