需要watch和connect
其中要注意,connect在grunt运行结束,任务就完成了,所以需要借助watch
贴个gruntfile.js的配置
module.exports = function(grunt) {
// 项目配置
grunt.initConfig({
watch: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: ['*.html', "*.js", "*.json", "*/*.js"],
tasks: ['connect']
},
connect: {
options: {
livereload: 35729,
port: 9000,
open: true
// ,
// base: 'www-root'
},
server: {}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
// 默认任务
grunt.registerTask('default', function(target) {
console.log("--BEGIN--");
grunt.task.run(['connect', 'watch']);
});
}