我个人更喜欢 grunt-contrib-watch ( https://github.com/gruntjs/grunt-contrib-watch ),因为它看起来更灵活。我在 Gruntfile.js 中定义了哪些文件应被监视以进行更改,并在此事件上订阅我想要执行的任何任务。
在开发上。环境项目页面具有重新加载脚本,该脚本使页面在 grunt-contrib-watch 触发的更新事件后立即刷新
<script src="http://localhost:35729/livereload.js"></script>
它对我来说很好。这是我的 grunt 构建脚本
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks('grunt-jscs');
grunt.initConfig({
// Lint all the files in js folder
jshint: {
options: {
jshintrc: ".jshintrc"
},
all: ["js/**/*.js"]
},
// Validate against jQuery coding standard
jscs: {
options: {
"standard": "Jquery"
},
all: ["js"]
},
// Preprocess SASS
compass: {
dist: {
options: {
sassDir: 'sass',
cssDir: 'css'
}
}
},
watch: {
options: {
livereload: true
},
css: {
files: ['sass/**/*.sass'],
tasks: ['compass']
},
js: {
files: ['js/**/*.js'],
tasks: ['jshint', 'jscs']
}
}
});
grunt.registerTask("lint", ["jshint", "jscs"]);
grunt.registerTask("default", ["watch"]);
};
当你运行 grunt 时,你会得到类似的东西