2015-08-31 45 views
0

我總是使用livereload和grunt for webapps,但突然大約一個月前它停止工作。我沒有做過與以前不同的事情。這是Livereload的錯誤還是我在這裏丟失了一些東西?大約一個月的時間,Livereload無法正常工作

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Sitename</title> 
    <link rel="stylesheet" type="text/css" href="css/app.css"> 
</head> 
<body> 
    <header> 
     <div class="logo"></div> 
    </header> 
    <section class="content"></section> 
    <div class="footer"> 

    </div> 
    <script src="//localhost:35729/livereload.js"></script> 
</body> 
</html> 

而且Gruntfile:

module.exports = function(grunt) { 
    grunt.initConfig({ 
    pkg: grunt.file.readJSON('package.json'), 

    sass: { 
     options: { 
     includePaths: ['bower_components/foundation/scss'] 
     }, 
     dist: { 
     options: { 
      outputStyle: 'compressed', 
      sourceMap: true, 
     }, 
     files: { 
      'css/app.css': 'scss/app.scss' 
     } 
     } 
    }, 

    watch: { 
     grunt: { 
     options: { 
      reload: true 
     }, 
     files: ['Gruntfile.js'] 
     }, 

     sass: { 
     files: 'scss/**/*.scss', 
     tasks: ['sass'] 
     } 
    } 
    }); 

    grunt.loadNpmTasks('grunt-sass'); 
    grunt.loadNpmTasks('grunt-contrib-watch'); 

    grunt.registerTask('build', ['sass']); 
    grunt.registerTask('default', ['build','watch']); 
} 

在控制檯中的錯誤:

[Error] Failed to load resource: Could not connect to the server. (livereload.js, line 0) 

和控制檯:

grunt 
Running "sass:dist" (sass) task 

Running "watch" task 
Waiting... 
>> File "scss/app.scss" changed. 
Running "sass:dist" (sass) task 

Done, without errors. 
Completed in 0.773s at Mon Aug 31 2015 17:53:46 GMT+0200 (CEST) - Waiting... 

,但仍然沒有重新加載。不知何故活重裝服務器不啓動,但實時重裝置設置爲true。有任何想法嗎?

+0

是什麼操作系統您使用的?當我使用Windows 10之前的Windows時,Livereload從未工作過 –

+0

您是否正在使用'grunt-contrib-connect'或其他來爲您的網頁提供測試? – James

+0

我測試了grunt-contrib-connect,但無法讓它正常工作。我只使用Apache的本地主機,從來沒有問題。端口80,在livereload集成到watch任務之前,我使用了livereload任務。 – Conjak

回答

0

傻我!我想念的livereload選項,在上海社會科學院配置:

options: { 
     livereload: true, 
    }, 

整個Gruntfile現在:

module.exports = function(grunt) { 
    grunt.initConfig({ 
    pkg: grunt.file.readJSON('package.json'), 

    sass: { 
     options: { 
     includePaths: ['bower_components/foundation/scss'] 
     }, 
     dist: { 
     options: { 
      outputStyle: 'compressed', 
      sourceMap: true, 
     }, 
     files: { 
      'css/app.css': 'scss/app.scss' 
     } 
     } 
    }, 

    watch: { 
     grunt: { 
     options: { 
      reload: true 
     }, 
     files: ['Gruntfile.js'] 
     }, 


     sass: { 
     files: 'scss/**/*.scss', 
     tasks: ['sass'], 
     options: { 
      livereload: true, 
     }, 
     } 
    } 
    }); 

    grunt.loadNpmTasks('grunt-sass'); 
    grunt.loadNpmTasks('grunt-contrib-watch'); 

    grunt.registerTask('build', ['sass']); 
    grunt.registerTask('default', ['build','watch']); 
} 
+0

向一個元素數組添加逗號時要小心。 –