这是我的 Gruntfile.js: /*全局模块*/
module.exports = function(grunt) {
'use strict';
// Load Grunt tasks declared in the package.json file
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
connect: {
all: {
options:{
port: 9000,
hostname: '0.0.0.0',
base: 'app',
keepalive: true,
livereload: true
}
}
},
less: {
development: {
files: {
'app/css/easier.css': 'app/less/easier.less'
}
}
},
watch: {
less: {
files: ['app/less/easier.less'],
tasks: ['less']
},
scripts: {
files: ['app/**/*.js'],
options: {
spawn: false,
livereload: true
}
}
}
});
grunt.registerTask('server',[
'connect',
'watch'
]);
};
我运行 grunt server
命令,我的文件得到了应有的服务。在另一个控制台中,我运行 grunt watch
,然后如果有任何更改,它会在浏览器中自动更改。是什么让这只用命令 grunt server
完成所有这些。我认为通过在服务器任务中添加任务 watch
可以解决这个问题,但它不起作用。我尝试仅通过 watch
任务在 Chrome 中启用 livereload
,但我收到一条警告,提示 Could not connect to LiveReload server。请确保 LiveReload 2.3(或更高版本)或其他兼容服务器正在运行。
我错过了什么?
最佳答案
设置keepalive
为false
,否则脚本会阻塞,不会执行watch
任务。
关于javascript - 我如何通过一个命令让 grunt 观看和 livereload - Gruntjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19769808/