1
我正在运行grunt-contrib-watch 0.6.1,并且在我的gruntfile.js中包含了livereload块。我还包括livereload.js调用我的html:grunt-contrib-watch livereload 35729 livereload.js无法加载
<script type="text/javascript" src="http://myste.com:35729/livereload.js"></script>
当我使用我的dev的包膜似乎一切都正常启动运行服务器。
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']);
};
您正在运行'concurent task'包括'watch'和'nodemon'任务和然后再次运行此任务。这可能会导致你的问题。检查如果你从'grunt dev'声明中删除它们会发生什么 – 2014-12-03 20:21:51
@GlenSwift谢谢你的建议。我试图从开发声明中删除它们,但是然后服务器无法启动。我也尝试删除从开发并发,加载服务器,但livereload访问仍然失踪。 – Finglish 2014-12-03 20:42:59
嗯,这是我的并发任务的实例: 并发:{ 任务:[ 'nodemon', '手表'], 选项:{ logConcurrentOutput:真 } } 我咕噜运行它,并做不单独运行watch和nodemon。我不确定这会有帮助,但你可以尝试吗?它对我来说非常合适。 – 2014-12-03 21:07:52