方案一:grunt-livereload + Chrome Plug-in
優點:安裝、配置簡單方便。
缺點:需要配合指定的瀏覽器插件(Firefox也有相關插件,IE么你懂的)。
1. 需要安裝2個插接件:grunt-contrib-watch、connect-livereload
執行命令:
2. 安裝瀏覽器插件:Chrome LiveReload
3. 配置一個Web服務器(IIS/Apache),LiveReload需要在本地服務器環境下運行(對file:///文件路徑支持并不是很好)。
4. 修改Gruntfile.js文件:
- module.exports = function(grunt) {
- // 項目配置(任務配置)
- grunt.initConfig({
- pkg: grunt.file.readJSON('package.json'),
- watch: {
- client: {
- files: ['*.html', 'css/*', 'js/*', 'images/**/*'],
- options: {
- livereload: true
- }
- }
- }
- });
- // 加載插件
- grunt.loadNpmTasks('grunt-contrib-watch');
- // 自定義任務
- grunt.registerTask('live', ['watch']);
- };
新聞熱點
疑難解答